jQuery update of asp:HiddenField fails to be persisted across postback

心不动则不痛 提交于 2019-12-06 01:13:57
Matthew Dresser

As mentioned in my edit, this issue is related to the fact that the hidden field (and everything else) is inside a div which is manipulated using the jQuery UI dialog method to create a popup window.

I found this question (HiddenField value modified by javascript is not posted back) which gave me the answer and involves adding a single line of code to the open: callback in the dialog methods constructor.

My JavaScript code for opening the dialog was modified as follows:

$('#MyDialog').dialog({
    closeOnEscape: true,
    open: function(event, ui) {
        $(this).parent().appendTo("form"); //this line sorted everything!
    }
}); 

To quote DanaBenson "I believe the root cause is that jQueryUI attaches dialogs to the BODY tag not the FORM tag, where .Net needs it to be."

Why not pass the value back as a postback parameter instead of a hidden field value, since you are just doing an immediate postback?

Try to use ClientID instead of UniqueID

__doPostBack('<%=lnkRedirectButton.ClientID%>', '');

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!