来自服务器端代码的 Jquery Messagebox 调用
我是 Jquery 新手,正在尝试开始学习这个新工具。我想要做的是在处理完成后从 gridViews Row Command 函数调用 JQuery 消息框,以便我可以通知用户该过程已完成。我试图使用这个网站作为参考 http://stuntsnippets.com/jquery-message-box/
但不知道如何调用来自服务器端的函数。我尝试过 ClientScript.RegisterStartupScript 谢谢你, Spafa9
将其放入您的脚本标签中...
$(document).ready(function () {
//Determining if there is a message to be shown if the message is not equal to empty string then the messagebox should appear.
if(message != '') {
message_box.show_message('Equipment Request:', message);
}
});
//JQuery to set up the messagebox.
var message_box = function () {
var button = '<input type="button" onclick="message_box.close_message();" value="Ok" />';
return {
show_message: function (title, body) {
if (jQuery('#message_box').html() === null) {
var message = '<div id="message_box"><h1>' + title + '</h1>' + body + '<br/>' + button + '</div>';
jQuery(document.body).append(message);
jQuery(document.body).append('<div id="darkbg"></div>');
jQuery('#darkbg').show();
jQuery('#darkbg').css('height', jQuery('html, body').height());
jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
jQuery('#message_box').show('slow');
} else {
var message = '<h1>' + title + '</h1>' + body + '<br/>' + button;
jQuery('#darkbg').show();
jQuery('#darkbg').css('height', jQuery('html, body').height());
jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
jQuery('#message_box').show('slow');
jQuery('#message_box').html(message);
}
},
close_message: function () {
jQuery('#message_box').hide('fast');
jQuery('#darkbg').hide();
}
}
} ();
这将出现在 CSS 中:
#darkbg {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: .5;
filter: alpha(opacity=50);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
#message_box {
width: 300px;
height: 150px;
background: #fff;
border: 4px solid #f0f0f0;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
position: absolute;
top: 100px;
left: 50%;
margin-left: -150px;
text-align: center;
z-index: 1000;
display: none;
}
#message_box input[type=button] {
float:left;
margin-left: 145px;
}
在您正在使用消息框的页面的回发中,将这行代码放入:
ltlMessage.Text = "<script type=""text/javascript"">var message = """"; </script>"
然后在您将在其中使用的函数下的行命令中喜欢显示消息框放置此代码。
ltlMessage.Text = "<script type=""text/javascript"">var message = ""Email has been sent.""; </script>"
I am new to Jquery and trying to start learning the new tool. What I want to do is call a JQuery message box from my gridViews Row Command function after the processing is done so I can notify the user the process has been complete. I was trying to use this website as a referance
http://stuntsnippets.com/jquery-message-box/
But not sure how to call the function from the serverside. I have tried ClientScript.RegisterStartupScript
Thank you,
Spafa9
Place this inside your script tags...
$(document).ready(function () {
//Determining if there is a message to be shown if the message is not equal to empty string then the messagebox should appear.
if(message != '') {
message_box.show_message('Equipment Request:', message);
}
});
//JQuery to set up the messagebox.
var message_box = function () {
var button = '<input type="button" onclick="message_box.close_message();" value="Ok" />';
return {
show_message: function (title, body) {
if (jQuery('#message_box').html() === null) {
var message = '<div id="message_box"><h1>' + title + '</h1>' + body + '<br/>' + button + '</div>';
jQuery(document.body).append(message);
jQuery(document.body).append('<div id="darkbg"></div>');
jQuery('#darkbg').show();
jQuery('#darkbg').css('height', jQuery('html, body').height());
jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
jQuery('#message_box').show('slow');
} else {
var message = '<h1>' + title + '</h1>' + body + '<br/>' + button;
jQuery('#darkbg').show();
jQuery('#darkbg').css('height', jQuery('html, body').height());
jQuery('#message_box').css('top', jQuery('html, body').scrollTop() + 150);
jQuery('#message_box').show('slow');
jQuery('#message_box').html(message);
}
},
close_message: function () {
jQuery('#message_box').hide('fast');
jQuery('#darkbg').hide();
}
}
} ();
this goes in the CSS:
#darkbg {
display: none;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: .5;
filter: alpha(opacity=50);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
#message_box {
width: 300px;
height: 150px;
background: #fff;
border: 4px solid #f0f0f0;
border-radius: 10px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
position: absolute;
top: 100px;
left: 50%;
margin-left: -150px;
text-align: center;
z-index: 1000;
display: none;
}
#message_box input[type=button] {
float:left;
margin-left: 145px;
}
In the if not is postback of the page you are using the message box on put this line of code:
ltlMessage.Text = "<script type=""text/javascript"">var message = """"; </script>"
Then in you row command under the function in which you would like to show the message box place this code.
ltlMessage.Text = "<script type=""text/javascript"">var message = ""Email has been sent.""; </script>"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我修改了我的帖子以包含工作示例。希望这可以帮助其他人。我忘记注意的一件事是,在您想要消息框的页面上,您将需要一个文字控件来保存消息,在我的例子中,它称为 ltlmessage。
斯帕法9
I have modifed my post to include the working example. Hope this helps someone else out. One thing I forgot to note is on the page in which you would like the message box you will need a literal control to save off the message in my case it is called ltlmessage.
Spafa9