简体   繁体   English

如何在asp.net中显示警告框

[英]how to display alert box in asp.net

i have a registration page with a submit button. 我有一个提交按钮的注册页面。

i want to show an alert box when the "user clicks on the submit button" after which the "data entered by the user is inserted in the database." 我希望在“用户点击提交按钮”时显示一个警告框,之后“用户输入的数据将插入数据库中”。

int i = obj.IU_SubscriberMaster(0, txtFirstname.Text, txtLastname.Text, txtEmail.Text, txtPassword.Text);

        if (i > 0)
        {
            Call ErrorTrap("errormsg");
        }

this is where i want to show the alert. 这是我想要显示警报的地方。 i used 我用了

    function alerts(str) {
    return false;
}

and than by creating a function errortrap 而不是通过创建一个函数errortrap

public void ErrorTrap(string str)
{
    if (!ClientScript.IsStartupScriptRegistered("alert"))
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);
    }
}

but it did not work 但它不起作用

can anyone please help? 有人可以帮忙吗?

Regular Page 常规页面

public void ErrorTrap(string str)
{
   Page.ClientScript.RegisterStartupScript(this.GetType(), "alert" + UniqueID, 
     "alert('" + str + "');", true);
}

Ajax Page Ajax Page

You need to use ScriptManager if you use ajax. 如果使用ajax,则需要使用ScriptManager。

public void ErrorTrap(string str)
{
   ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert" + UniqueID, 
      "alert('" + str + "');", true);
}

alerts : alerts

Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alerts('" + str + "');", true);

needs to be alert : 需要alert

 Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str + "');", true);

Did you mean for the javascript to be "alerts("+ str + "');" 你的意思是javascript是"alerts("+ str + "');" and not "alert(" + str + "');" 而不是"alert(" + str + "');" ?

alerts should be alert . alerts应该alert if you are using ajax, better use ScriptManager. 如果您使用的是ajax,请更好地使用ScriptManager。

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

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