App_Code class: Set Focus on control


S

sck10

Hello,

I am trying to add the following to a App_Code class. The error I am
getting is "The name 'ClientScript' does not exist in the current context".
I would like to call this from my content page which uses MasterPages. Any
help with this would be appreciated...

Thanks, sck10

public 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(this.GetType(), "SetFocusControl",
script.ToString());

}
 
Ad

Advertisements

W

Walter Wang [MSFT]

Hi,

ClientScript is a property of the Page class.

You can use "FocusControl.Page.ClientScript.RegisterStartupScript(...)".

Hope this helps. Please feel free to post here if anything is unclear.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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