Set Focus using: Clientscript.RegisterStartupscript


S

sck10

Hello,

I am trying to set the focus on an object using the following: However, I
am getting the following error:

The name Clientscript does not exist in the current context.

protected void SetFocusControl(Control FocusControl)
{
StringBuilder script = new StringBuilder();
string ClientID = FocusControl.ClientID;
script.Append("<script language='javascript'>");
script.Append("document.getElementById('");
script.Append(ClientID);
script.Append("').focus();");
script.Append("</script>");
Clientscript.RegisterStartupscript("SetFocusControl", script);
}
 
Ad

Advertisements

J

John Timney \(MVP\)

try it with the correct case

ClientScript.RegisterStartupscript("SetFocusControl", script);
 
Ad

Advertisements

D

dgk

Thanks John...

With 2.0, controls have a Focus method that seems to do the same
thing. Actually a bit better because it takes care of ClientId if
using a master page.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top