JQuery modal pop-up doesn't raise values โ€‹โ€‹in click handler

I am using Basic Modal Dialog in my ASP.NET web application. In the pageload event pageload it correctly binds data to text fields inside a modal popup. But when I try to get the values โ€‹โ€‹from the text fields in the buttonclick event buttonclick , it just returns empty lines as the value.

Basically, such code contains text fields inside a div that pop up:

 <asp:TextBox ID="fname" runat="server"></asp:TextBox> 

In pageload:

 fname.Text = customer.firstName; this is working 

Press the button:

 protected void BtnSaveinfoClick(object sender, EventArgs e) { var firstname = fname.Text.Trim();// this taking values as "" } 

I did breakpoint in buttonclick . when I hover over the fname text box with firebug , it showed me the value.

 <input id="MainContent_cphMain_PersonalInfo1_fname" type="text" value="Andrew" name="ctl00$ctl00$MainContent$cphMain$PersonalInfo1$fname"> 

Any ideas would be helpful.

+4
source share
3 answers
0
source

You must use the appendTo parameter to add a dialog box to the form for ASP.NET events:

appendTo [String: 'body']

JQuery selector to add items to. For ASP.NET use the "form".

NOTE. JQuery UI dialogs are added to the body tag by default. All .NET controls must appear inside the form tag for it to work properly. For the exercise, try adding any control (that is: asp: textbox) to the page with runat = "server", outside the form tag and see what ASP.NET has to say about it.

+1
source

Have you checked your Page_Load and other scripts to make sure you are not clearing fname at any time before it reaches the event?

0
source

All Articles