Discussion:
Set Focus using: Clientscript.RegisterStartupscript
(too old to reply)
sck10
19 years ago
Permalink
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);
}
John Timney (MVP)
19 years ago
Permalink
try it with the correct case

ClientScript.RegisterStartupscript("SetFocusControl", script);

--
Regards

John Timney (MVP)
...
sck10
19 years ago
Permalink
Thanks John...
...
dgk
19 years ago
Permalink
Post by sck10
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.

Loading...