如何在 SimpleModal 对话框中显示值?
我的问题很简单。我有一个 asp.net 按钮。我可以用它来调用 simpleModal 并显示一个对话框。现在,我在对话框中添加了一个标签控件,并希望该标签显示一些值。我应该怎么办?
这是我的代码
$('#<%= btnOpen.ClientID %>').click(function(e) {
e.preventDefault();
$('#content').modal({
onOpen: function(dialog) {
dialog.overlay.fadeIn('slow', function() {
dialog.data.hide();
dialog.container.fadeIn('slow', function() {
dialog.data.slideDown('slow');
});
});
},
onClose: function(dialog) {
dialog.data.fadeOut('slow', function() {
dialog.container.slideUp('slow', function() {
dialog.overlay.fadeOut('slow', function() {
$.modal.close(); // must call this!
});
});
});
}
});
e.preventDefault();
// return false;
});
<asp:Button ID="btnOpen" runat="server" Text="ASP.NET Open"/>
<div id="content" style="display: none;">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
my question is really simple. I have a asp.net button. I can use it to call the simpleModal and have a dialog displayed. Now, I added a label control in the dialog, and would like this label to display some value. What should I do?
Here is my codes
$('#<%= btnOpen.ClientID %>').click(function(e) {
e.preventDefault();
$('#content').modal({
onOpen: function(dialog) {
dialog.overlay.fadeIn('slow', function() {
dialog.data.hide();
dialog.container.fadeIn('slow', function() {
dialog.data.slideDown('slow');
});
});
},
onClose: function(dialog) {
dialog.data.fadeOut('slow', function() {
dialog.container.slideUp('slow', function() {
dialog.overlay.fadeOut('slow', function() {
$.modal.close(); // must call this!
});
});
});
}
});
e.preventDefault();
// return false;
});
<asp:Button ID="btnOpen" runat="server" Text="ASP.NET Open"/>
<div id="content" style="display: none;">
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想既然你说你的问题很简单,你只是不熟悉 jQuery。您可以将其放入
click
函数或$(document).ready
函数中,具体取决于您的完整要求:注意:您需要使用
.html 而不是
.text
,但.text
速度更快。I assume since you said that your question is simple that you just have an unfamiliarity with jQuery. You can put this in your
click
function, or in the$(document).ready
function, depending on your full requirements:Note: You'll need to use
.html
instead of.text
if you have a string with tags, but.text
is faster.哈哈,我再次回答我自己的问题,但我还是把功劳归功于 mNVhr。
我终于把整个事情搞定了。 asp.net 按钮触发回发以及 javascript 回发的技巧是将 asp.net 按钮放入更新面板中。这是我的代码
对于javascript部分:
对于HTML标记
对于后面的代码:
我希望这个小代码可以帮助那些asp希望在项目中使用漂亮的 jQuery 的 .net 开发人员。
Lol, I am answering my own question again, but I will give credit to mNVhr tho.
I finally get the whole thing work. The trick for asp.net button to fire a postback, along with javascript's postback, is to put the asp.net button into an update panel. Here is the code I have
For the javascript part:
For the HTML markup
For the code behind:
I hope this tiny code can help those asp.net developer who want to use the nice jQuery in their projects.
从上面的代码可以看出。
当我单击 btnOpen 按钮时,会触发两个回发。一种是来自 asp.net 后面的代码,它将当前日期时间分配给模式对话框内的文本框控件。第二个回发来自 javascript,它打开模式对话框。 asp.net 按钮必须位于更新面板内。否则,模态对话框只会停留约 0.5 秒。
当我单击模式对话框内的 btnSave 时。回发也发生了。我这里有一点逻辑。当文本框的值为 1 时,我调用 closeDialog() 函数。当值为其他数字时,模式对话框保持打开状态,对话框内的标签控件将显示文本框中的数字。
jQuery 很好,但作为一个 .Net 开发人员,它只是新的,有时对我来说很难理解它,特别是对于 javascript 和 .net 之间的回发冲突。
我希望这个答案有帮助。
As you can see, from the above codes.
When I click on the btnOpen button, two postbacks fired. One is from the asp.net code behind, which assign current datetime to the textbox control inside the modal dialog. The second postback is from the javascript, which open the modal dialog. The asp.net button has to be inside the update panel. Otherwise, the modal dialog will only stay for about 0.5 second.
When I click on the btnSave inside the modal dialog. Postback also occurred. I have a little logic here. When the textbox's value is 1, I call the closeDialog() function. When the value is other numbers, the modal dialog stay opening, and the label control inside the dialog will display the number from the text box.
jQuery is nice, but as a .Net developer, it is just new, and sometimes difficult for me to understand it, especially for the conflict of postbacks between javascript and .net.
I hope this answer is helpful.