ali raza

C#, .Net ,Asp.net and my thoughts

Place Cursor in the First Input Box Automatically

protected void Page_Load(object sender, EventArgs e)
 {    FindFirstTextBox(this); }
 private bool FindFirstTextBox(Control ctl)
 {    bool foundControl = false;
    foreach (Control child in ctl.Controls)
    {
      if (child is TextBox)
       {
         System.Text.StringBuilder script =             new System.Text.StringBuilder();
          script.AppendFormat("function findFirstControl()\n{1}\n document.getElementById(\"{0}\").focus();\n{2}\n",             child.ID, "{", "}");
        ClientScript.RegisterClientScriptBlock(this.GetType(),"findFirstControl", script.ToString(), true);
          foundControl = true;
          break;
       }
    if (FindFirstTextBox(child))
      {
       foundControl = true;
         break;
       }
     }
  return foundControl;
 }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: