JQuery UI Dialog and __DoPostback
I have a problem with a 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 ASP.NET TextBox
.
When I click OK, the form is returned, but the textbox is irrelevant.
jQuery moves the field outside of the <form> why you can't see the value to post back.
You have two options:
- Add code to move the div dialog back to the form before calling __doPostBack - you can use something like $ ("form") [0] .appendChild ($ ("div.yourdivdialog input: first") [0]); for this.
- Add a hidden field to your form (but not the dialog div) and add code to copy your dialog boxes to the hidden field before __doPostBack.
source to share
I know you have probably already checked that the object name is what you wrote (ctl00 $ phContent $ ctl00 $ LetterLocation $ pupNewReceiver), but the first thing I would do would be to double or triple the check ...
I once spent almost one 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 the client object name.
Check the Request.Params collection to make sure the name is correct.
You can also use the second parameter of the __doPostBack function to specify the value you want to post back
Here's an example of what I usually do:
__ doPostBack ($ ("# <% = Me.btnDeleteItem.ClientID%>"). attr ("name"), $ ("# <% = txtId.ClientID%>"). val ());
source to share
I cannot answer a specific question. However, I highly recommend changing your code to use asp.net to insert an object id like vitorsilva - ie <% = 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) may change if you change the page structure. By using the ClientID method, you will always get the correct ID.
source to share