在jQuery对话框中,asp.net表单控件不可读,如何解决? [英] asp.net form controls are unreadable when in a jQuery dialog, how do you fix it?
问题描述
我有一个多刺的人.我有一个asp.net Web表单页面.在页面中,我有一个div标记,已将其设置为jQuery对话框.在div中有一些jQuery控件.我打开对话框,单击其中一个按钮开始回发.页面发回时,隐藏的代码尚未读取控件中的值.当然,深入研究html会发现该对话框占用了我的div,并将其移动到html页面底部,而不是我的asp.net表单标签. rk!
I've got a prickly one. I have an asp.net web forms page. In the page I have a div tag that I've set to be used as a jQuery dialog. In the div is some jQuery controls. I get the dialog to open up and clicking on one of the buttons commences postback. When the page was posting back the code-behind hasn't been reading the values in the controls. Of course a little delving into the html reveals that the dialog takes my div and moves it to the bottom of the html page OUTSIDE my asp.net form tag. Urk!
我该怎么办?
在这里我的对话代码不能真正帮助解决这种情况:
Not that it really helps the situation by my dialog code is here:
$("#dialog-copy").dialog({
autoOpen: false,
height: 200,
width: 400,
modal: true,
resizable: false,
buttons: {
'Cancel': function () {
$(this).dialog('close');
},
'Yes': function () {
$(this).dialog('close');
$("[id*=btnCopy]")[0].click();
}
},
open: function () {
$(":button:contains('Yes')").addClass("blue");
}
});
$("[id*=btnCopy]").live('mousedown', function (e) {
e.preventDefault();
$("#dialog-copy").dialog('open');
});
一个典型的div标签(已移到我的表单标签之外)看起来像这样:
And a typical div tag (that is moved to outside my form tag) is looking like this:
<div id="dialog-copy" style="DISPLAY: none" title="Copy Schedule">
<p>Please enter a schedule number:</p>
<asp:Textbox runat="server" id="txtSchNo"></asp:Textbox>
</div>
点击是"会触发调用回发的按钮.
Clicking 'Yes' fires the button that calls the postback.
推荐答案
这是一个已知问题,您必须将其附加到这样的表单中,并且您的常规.NET控件可以回发:
It's a known issue, you have to append it to the form like this and your normal .NET controls can postback:
open: function () {
$(this).parent().appendTo("form");
$(":button:contains('Yes')").addClass("blue");
}
更新以更新jQuery:
UPDATE for newer versions of jQuery:
$('#yourDIv').dialog({
.....,
appendTo: $('form'),
....
});
这篇关于在jQuery对话框中,asp.net表单控件不可读,如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!