简体   繁体   English

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

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

How to display Bootstrap Autocloseable alert message on asp.net button click? 如何在asp.net按钮单击上显示Bootstrap Autocloseable警报消息?

Code as follows: 代码如下:

 <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>

closeable code using javascript 使用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>

I called function name"showalertmsg" on asp button click it gives error? 我在asp按钮上调用了函数名“ showalertmsg”,单击它会出错吗? error gives as follows while compiling 编译时错误如下

Compiler Error Message: CS1026: ) expected

Issues in the asp.net button 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;" />

you can't call javascript fuction like this 你不能像这样调用javascript功能

OnClick="btnLogin_Click showalertmsg();"

But

use OnClientClick="showalertmsg();" 使用OnClientClick="showalertmsg();"

and also call return false at the end to stop postback 并在最后调用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