asp.net上的按钮事件中的自举警报 [英] Bootstrap alert in button event on asp.net

查看:69
本文介绍了asp.net上的按钮事件中的自举警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何编写代码,当我单击asp.net上的按钮时,出现引导程序或消息框的警报消息?

How could I make a code that when I click a button on asp.net, an alert message of bootstrap or message box appears?

protected void ButtonLogin_Click(object sender, EventArgs e)
    {
        //TextBoxEmail.Text = DateTime.Now.ToString();
        string UserName = TextBoxEmail.Text.Trim();
        string password = TextBoxPassword.Text.Trim();
        OracleConnection conn = new OracleConnection(strConnString);
        conn.Open();

        sql = "select password from userlogin where USERNAME = '" + UserName + "' and password ='" + password + "' ";
    cmd = new OracleCommand(sql, conn);


    // orada=new OracleDataAdapter(com.CommandText,conn);
    // cmd.CommandType = CommandType.Text;
    dr = cmd.ExecuteReader();
    //dr.Read();

    if (dr.HasRows)
    {
        Label1.Text = "";
        Response.Redirect("Details.aspx");
    }
    else
    {
        Label1.Text = "No data found...";
        conn.Close();
    }

   }

}

上面,在else部分:

Above, in the else portion:

 else
         {
             Label1.Text = "No data found...";
             conn.Close();
         }

当用户名和密码不匹配时,我希望引导警报或消息框出现在网站上:密码不正确".我该怎么办?

When username and password don't match, I want a bootstrap alert or message box to appear on the website: "password is not correct". How could I do that?

推荐答案

为此,您需要引用引导程序链接和jquery

For this you need to reference the bootstrap links and jquery

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>

下一步将其添加到Aspx页面的头部:

Next Add this to your Head Section in Aspx Page:

 <style type="text/css">
        .messagealert {
            width: 100%;
            position: fixed;
             top:0px;
            z-index: 100000;
            padding: 0;
            font-size: 15px;
        }
    </style>
    <script type="text/javascript">
        function ShowMessage(message, messagetype) {
            var cssclass;
            switch (messagetype) {
                case 'Success':
                    cssclass = 'alert-success'
                    break;
                case 'Error':
                    cssclass = 'alert-danger'
                    break;
                case 'Warning':
                    cssclass = 'alert-warning'
                    break;
                default:
                    cssclass = 'alert-info'
            }
            $('#<%=ButtonLogin.ClientID %>').append('<div id="alert_div" style="margin: 0 0.5%; -webkit-box-shadow: 3px 4px 6px #999;" class="alert fade in ' + cssclass + '"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>' + messagetype + '!</strong> <span>' + message + '</span></div>');
        }
    </script>

使用Cs代码

  protected void ShowMessage(string Message, MessageType type)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), "ShowMessage('" + Message + "','" + type + "');", true);
    }

现在在 else 中,可以使用部分调用错误功能,也可以通过更改消息类型来成功使用此功能

Now in else Part call Error function, in succes also you can use this function by changing the Message type

ShowMessage("Aww, password is wrong", MessageType.Error);

这篇关于asp.net上的按钮事件中的自举警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆