Thursday, July 15, 2010

Set Focus on Textbox in modalPopup Panel

Add following code in my Page_Load :
StringBuilder sb = new StringBuilder();
sb.Append("<script type=\"text/javascript\">\n");
sb.Append("Sys.Application.add_load(modalSetup);\n");
sb.Append("function modalSetup() {\n");
sb.Append(String.Format("var modalPopup = $find('{0}');\n", ModalPopupExtender1.BehaviorID));
sb.Append("modalPopup.add_shown(SetFocusOnControl); }\n");
sb.Append("function SetFocusOnControl() {\n");
sb.Append(String.Format("var textBox1 = $get('{0}');\n", tbMyTextbox.ClientID));
sb.Append("textBox1.focus();}\n");
sb.Append("script>\n");
Page.ClientScript.RegisterStartupScript(Page.GetType(), "Startup", sb.ToString());

No comments:

Post a Comment