views:

2499

answers:

5

Hi All

I have a problem with the jquery-ui dialog in 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 in the OK button, the form posts back but the textbox doesn't have value.

Thanks and sorry for bad English

+1  A: 

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

vitorsilva
A: 

Hi, 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.

Nima
A: 

I can't answer the speific question. However, I highly recommend changing your code to use asp.net 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.

Dr8k
A: 

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.

Salamander2007
+1  A: 

jQuery dialog does move the field outside of the <form> which why you are not seeing the value on postback.

You have two options:

  1. 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.
  2. 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.
Hafthor