Setting focus on control in webform

R

reidarT

I have a webform and found some code where I understand some of it, but not
all
The code is as follows
public static void SetFocus(Control control)
{
StringBuilder sb = new StringBuilder();

sb.Append("\r\n<script language='JavaScript'>\r\n");
sb.Append("<!--\r\n");
sb.Append("function SetFocus()\r\n");
sb.Append("{\r\n");
sb.Append("\tdocument.");

Control p = control.Parent;
while (!(p is System.Web.UI.HtmlControls.HtmlForm)) p = p.Parent;

sb.Append(p.ClientID);
sb.Append("['");
sb.Append(control.UniqueID);
sb.Append("'].focus();\r\n");
sb.Append("}\r\n");
sb.Append("window.onload = SetFocus;\r\n");
sb.Append("// -->\r\n");
sb.Append("</script>");

control.Page.RegisterClientScriptBlock("SetFocus", sb.ToString());
}
The code results in adding Javascript to your page as follows:


<script language='JavaScript'>
<!--
function SetFocus()
{
document.Form1['TextBox1'].focus();
}
window.onload = SetFocus;
// -->
</script>
But you don't need to care about that because all you need to do to use it
is call your static method from your code behind class:


PageUtility.SetFocus(TextBox1);I have converted it to VB. What I don't
understand is the last one sentence with the first word PageUtilityWhat is
it for?regardsreidarT
 
R

reidarT

I found the solution myself. PageUtility means only Me
Sorry for the inconvenience.
regards
reidarT
 

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