繁体   English   中英

如何在asp.net按钮单击上显示Bootstrap Autocloseable警报消息?

[英]How to display Bootstrap Autocloseable alert message on asp.net button click?

如何在asp.net按钮单击上显示Bootstrap Autocloseable警报消息?

代码如下:

 <div>
    <asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="btn btn-block org"
        Style="margin-top: 0px" OnClick="btnLogin_Click showalertmsg();" ValidationGroup="Login" />
</div>

使用javascript关闭代码

 <script type="text/javascript">
    function showalertmsg(message, alerttype) {

        $('#alert_placeholder').append('<div id="alertdiv" class="alert ' + alerttype + '"><a class="close" data-dismiss="alert">×</a><span>' + message + '</span></div>')

        setTimeout(function () {
            $("#alertdiv").remove();

        }, 5000);
    }
</script>

我在asp按钮上调用了函数名“ showalertmsg”,单击它会出错吗? 编译时错误如下

Compiler Error Message: CS1026: ) expected

asp.net按钮中的问题

<asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="btn btn-block org"
        Style="margin-top: 0px" OnClick="btnLogin_Click" ValidationGroup="Login" OnClientClick="showalertmsg(); return false;" />

你不能像这样调用javascript功能

OnClick="btnLogin_Click showalertmsg();"

使用OnClientClick="showalertmsg();"

并在最后调用return false停止回发

function showalertmsg(message, alerttype) {

        $('#alert_placeholder').append('<div id="alertdiv" class="alert ' + alerttype + '"><a class="close" data-dismiss="alert">×</a><span>' + message + '</span></div>')

        setTimeout(function () {
            $("#alertdiv").remove();

        }, 5000);

return false;
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM