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.

+1


source to share


6 answers


Dialog window

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.
+4


source


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 ());

+2


source


JQuery Script encapsulated in an ASP.Net custom control and using Page.ClientScript.GetPostBackEventReference (this, ""). pnlReceiverDialog is a DIV out of control.

I checked Request.Params, TextBox value doesn't exist.

0


source


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.

0


source


Is this a read-only or disabled or hidden text box? ASP.NET does not return a value if the text box is in "readonly", "disabed", or "hidden" mode.

0


source


I believe the textbox is irrelevant because it is outside the form.

Try using the following code to add Modal to your form:

$("#ModalId").parent().appendTo(jQuery("form:first"));

      

0


source







All Articles