我正在尝试在PostBack期间显示消息栏。 我正在使用在线找到的jQuery脚本(在此处)。 一切工作都很好,但是当将jQuery添加到页面时,我的服务器端事件从未被调用。
这是我的按钮代码:
<asp:Button ID="btnGetReport" CssClass="float-left" runat="server"
Text="<%$ Glossary:GetReport %>" OnClick="btnGetReport_Click" />
这是内联脚本:
<script type="text/javascript">
$(document).ready(function () {
$('#<%=btnGetReport.ClientID%>').click(function (event) {
event.preventDefault();
$('#message_bar').displayMessage({
position: 'fixed',
skin: 'modern',
message: 'We are fetching your report. Please wait...',
});
});
});
</script>
这是相关的外部 .js 文件:
(function( $ ){
$.fn.displayMessage = function(options) {
// Default configuration properties.
var defaults = {
message : 'Error message',
speed : 'fast',
position : 'fixed', // relative, absolute, fixed
autohide : true
}
var options = $.extend( defaults, options );
$(this).slideUp('fast');
$(this).removeClass().empty();
return this.each(function() {
var sticky = (options.sticky == false) ? 'relative' : 'absolute';
$(this).addClass('messagebar-skin-'+options.skin+'_bar').css('position',options.position).css('background-color',options.background);
$(this).append('<div class="messagebar-skin-'+options.skin+'_inner"><span class="messagebar-skin-'+options.skin+'_text"></span></div>').css('color',options.color);
$(this).find('span').html(options.message);
$(this).slideDown(options.speed ,function(){
var parent = ($(this).attr('id')) ? "#"+$(this).attr('id') : "."+$(this).attr('class');
var close_button = ($(this).find('a').attr('id')) ? "#"+$(this).find('a').attr('id') : "."+$(this).find('a').attr('class');
if(options.autohide == true)
{
$(this).delay(2400).fadeOut('slow');
}
$(parent+">div>"+close_button).bind("click", function (event) {
event.preventDefault();
$(parent+">div>"+close_button).animate({"opacity": "hide"}, function(){
$(parent+">div>span").fadeOut("slow").html("");
$(parent+">div>"+close_button).parent().parent().slideUp(options.speed);
});
});
});
});
};
})( jQuery );
我还尝试使用OnClientClick属性调用函数,但两种方式似乎都不起作用。我查看了其他人遇到问题的例子,但它们都没有帮助。
如果您有任何想法,请不吝赐教!