By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

How to set focus on textbox inside modal popup

P: 1
I want to set focus for the textbox on poup window is visible on clicking a link.
<a href="#" data-toggle="modal" data-target="#contactForms">request</a>


modal id #contactForms"
Nov 30 '15 #1
Share this Question
Share on Google+
2 Replies


100+
P: 293
Hi,

This is not possible unless the target control is activated.

This link might be helpful.

Please let me know if this doesn't help.
Dec 6 '15 #2

P: 18
Hey,I am sharing a code,try this:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3.       if (!Page.IsPostBack)
  4.       {
  5.             if (!this.ClientScript.IsStartupScriptRegistered("startup"))
  6.             {
  7.                   StringBuilder sb = new StringBuilder();
  8.                   sb.Append("&lt;script type='text/javascript'>");
  9.                   sb.Append("Sys.Application.add_load(modalSetup);");
  10.                   sb.Append("function modalSetup() {");
  11.                   sb.Append(String.Format("var modalPopup = $find('{0}');", popupEntry.BehaviorID));
  12.                   sb.Append("modalPopup.add_shown(SetFocusOnControl); }");
  13.                   sb.Append("function SetFocusOnControl() {");
  14.                   sb.Append(String.Format("var textBox1 = $get('{0}');", txtValue.ClientID));
  15.                   sb.Append("textBox1.focus();}");
  16.                   sb.Append("&lt;/script>");
  17.                   Page.ClientScript.RegisterStartupScript(Page.GetType(), "startup", sb.ToString());
  18.              }
  19.       }
  20. }
Jan 13 '16 #3

Post your reply

Sign in to post your reply or Sign up for a free account.