4

I am using the Basic Modal Dialog in my ASP.NET web application. In the pageload event handler, it correctly binds the data to the text boxes which are inside the modal popup. But when I try to retrieve the values from the text boxes in the buttonclick event handler, it just returns empty strings as the value.

The code is basically like this have text boxes inside a div which pop-up:

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

In pageload:

fname.Text = customer.firstName; this is working

In button click:

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

I did make a breakpoint in the buttonclick. when i hover over the fname text box with the firebug it showing me the value is there.

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

Any ideas will be helpful.

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99

3 Answers3

1

You have to use the appendTo option to append the dialog to the form for ASP.NET events to fire:

appendTo [String:'body']

The jQuery selector to append the elements to. For ASP.NET, use 'form'.

NOTE: jQuery UI Dialogs get appended the to the body tag by default. All .NET controls must be rendered inside the form tag to work properly. For an exercise, try adding any control(ie: asp:textbox) to a page that has runat="server", outside of the form tag and see what ASP.NET has to say about it.

rick schott
  • 21,012
  • 5
  • 52
  • 81
  • Could be the reason, though the question does seem to suggest the event is firing but that fname is empty. – Kasaku Oct 07 '11 at 09:01
  • They said buttonclick did not fire. – rick schott Oct 07 '11 at 09:03
  • this is correct. this pop-up is inside a WebUserControler. the page structure is Masterpage -> sub masterpage -> .aspx page -> controler(with the pop up). When i looked at the page source in runtime it appear that the popup is outside the form tag and inside the body – huMpty duMpty Oct 07 '11 at 09:11
  • 1
    Rick, fair enough, didn't post that. Oddly enough, answered a question on this just yesterday :) http://stackoverflow.com/questions/7672890/aspbutton-click-event-is-not-firing/7673768#7673768 – Kasaku Oct 07 '11 at 09:17
  • Yeah, since the user is using a wrapper plug-in for the dialog, although the same issue, the solution a tad different. – rick schott Oct 07 '11 at 09:43
0

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

Kasaku
  • 2,192
  • 16
  • 26
0

This is what happenes Fix your postbacks in Modal forms

huMpty duMpty
  • 14,346
  • 14
  • 60
  • 99