I have a problem with the jQuery-UI dialog in my ASP.NET form:
$("#pnlReceiverDialog").dialog({
autoOpen:false,
modal: true,
height:220,
width:500,
resizable :false,
overlay: { opacity: 0.5,background: "black" },
buttons: {
"Cancel": function() {
$(this).dialog("close");
},
"Ok": function() {
__doPostBack('ctl00$phContent$ctl00$LetterLocation$pupNewReceiver','')
}
}
});
pnlReceiverDialog
contains an ASP.NET TextBox
.
When I click on the OK button, the form posts back but the textbox doesn't have a value.
I have a problem with the jQuery-UI dialog in my ASP.NET form:
$("#pnlReceiverDialog").dialog({
autoOpen:false,
modal: true,
height:220,
width:500,
resizable :false,
overlay: { opacity: 0.5,background: "black" },
buttons: {
"Cancel": function() {
$(this).dialog("close");
},
"Ok": function() {
__doPostBack('ctl00$phContent$ctl00$LetterLocation$pupNewReceiver','')
}
}
});
pnlReceiverDialog
contains an ASP.NET TextBox
.
When I click on the OK button, the form posts back but the textbox doesn't have a value.
Share Improve this question edited Oct 26, 2013 at 13:12 ProgramFOX 6,40011 gold badges48 silver badges54 bronze badges asked Dec 16, 2008 at 11:53 user39880user398806 Answers
Reset to default 4jQuery dialog does move the field outside of the <form> which why you are not seeing the value on postback.
You have two options:
- Add code to move the dialog div back into the form before invoking __doPostBack -- you can use something like $("form")[0].appendChild($("div.yourdivdialog input:first")[0]); to do that.
- Add a hidden field in your form (but not in the dialog div) and add code to copy your dialog field(s) to the hidden field before __doPostBack.
I know that you probably already checked that the object name is the one that you wrote (ctl00$phContent$ctl00$LetterLocation$pupNewReceiver) but the first thing that i would do is to double or triple check it...
i once spent almost a day in a similar situation where the only thing that was wrong was the object name because there was a difference between the client object id and client object name.
Check the Request.Params collection to make sure that the name is right.
You can also use the second parameter of the __doPostBack function to specify the value that you want to postback
Here is an exemple of what i usually do:
__doPostBack($("#<%=Me.btnDeleteItem.ClientID %>").attr("name"), $("#<%=txtId.ClientID%>").val());
JQuery Script encapsulated in the ASP.Net custom Control and use Page.ClientScript.GetPostBackEventReference(this,""). pnlReceiverDialog is a DIV outside the control.
I was checked the Request.Params, value of the TextBox dosn't exist.
I can't answer the speific question. However, I highly remend changing your code to use asp to insert the object id like vitorsilva did - i.e. <%=TEST.ClientID %> where TEST is the ASP.Net ID of your textbox or whatever. The actual object id sent to the browser (i.e. ctl00$phContent$ctl00$LetterLocation$pupNewReceiver in your example) can change if you change the page structure. By using the ClientID method you will always get the correct ID rendered.
Is it a read-only or disabled or hidden textbox? ASP.NET doesn't postback the value if the textbox is readonly, disabed, or hidden.
I believe that the textbox has no value because it ends up outside the form.
Try use the following code to add the Modal to the form:
$("#ModalId").parent().appendTo(jQuery("form:first"));