如何显示在asp.net警告框 [英] how to display alert box in asp.net

查看:194
本文介绍了如何显示在asp.net警告框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个提交按钮注册页面。

我要显示一个警告框,当用户点击提交按钮之后,数据用户输入被插入到数据库中。

  INT I = obj.IU_SubscriberMaster(0,txtFirstname.Text,txtLastname.Text,txtEmail.Text,txtPassword.Text);        如果(I 0)
        {
            呼叫ErrorTrap(ERRORMSG);
        }

这就是我想要显示的警报。
我用

 功能警报(STR){
    返回false;
}

和比创建一个函数errortrap

 公共无效ErrorTrap(字符串str)
{
    如果(!ClientScript.IsStartupScriptRegistered(警告))
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(),警戒,警报('+ STR +');,真正的);
    }
}

但它没有工作。

任何人都可以请帮助?


解决方案

常规页

 公共无效ErrorTrap(字符串str)
{
   Page.ClientScript.RegisterStartupScript(this.GetType(),提醒+ UniqueID的,
     警报('+ STR +');,真正的);
}

AJAX页面

您需要,如果你使用AJAX使用ScriptManager的。

 公共无效ErrorTrap(字符串str)
{
   ScriptManager.RegisterStartupScript(页,Page.GetType(),警戒+ UniqueID的,
      警报('+ STR +');,真正的);
}

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

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

You need to use ScriptManager if you use ajax.

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

这篇关于如何显示在asp.net警告框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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