Welcome to MSDN Blogs Sign in | Join | Help

How to set focus on the asp.net textbox in AxPopup form?

To set the focus include this method in your page that is opened in the popup window and call the method without control name in the page load event.

For example to set the focus on txtCustAccount

 

protected void Page_Load(object sender, EventArgs e)

    {

       

        SetFocus(txtCustAccount);

    }

 

public static void SetFocus(Control control)

    {

        StringBuilder sb = new StringBuilder();

 

        sb.Append("<script language='JavaScript'>");

        sb.Append("function SetFocus(){document.");

 

        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();}");

       

        sb.Append("window.onload = SetFocus;</script>\r\n");

 

        control.Page.RegisterClientScriptBlock("SetFocus", sb.ToString());

    }

Published Wednesday, October 21, 2009 11:31 PM by meysun
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker