在 jQuery 对话框中时,asp.net 表单控件不可读,如何修复它?
我有一个带刺的。我有一个 ASP.NET Web 表单页面。在页面中,我有一个 div 标签,我已将其设置为用作 jQuery 对话框。 div 中是一些 jQuery 控件。我打开对话框并单击其中一个按钮开始回发。当页面回发时,隐藏代码尚未读取控件中的值。当然,稍微深入研究一下 html 就会发现,该对话框将我的 div 移至 html 页面的底部,位于我的 asp.net 表单标记之外。乌尔克!
我到底该如何解决这个问题?
并不是说它确实对我的对话框代码有帮助,如下所示:
$("#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 标签(移至表单标签之外)如下所示:
<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>
单击“是”会触发调用回发的按钮。
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!
How the hell do I get around this?
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');
});
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个已知问题,您必须将其附加到这样的表单中,并且您的普通 .NET 控件可以回发:
更新版本的 jQuery:
It's a known issue, you have to append it to the form like this and your normal .NET controls can postback:
UPDATE for newer versions of jQuery:
让您的对话框按钮功能在提交表单之前使用正确的名称向表单添加一个隐藏字段,即使用对话框本身中的输入作为参考。
Have your dialog button function add a hidden field to the form with the correct name, i.e., using the input in the dialog itself for reference, before it submits the form.
你可以试试这个。在对话框中保留常规的 html 输入,然后在单击回发按钮之前将 html 文本输入中的值移动到 asp:TextBox 或就此而言甚至是 asp:HiddenInput。
喜欢:
和标记:
You could try this. Keep a regular html input within the dialog and just before clicking the postback button move the value within the html text input to the asp:TextBox or for that matter even a asp:HiddenInput.
Like:
And the markup: