在AJAX环境中弹出提示框

来源:互联网 发布:苹果如何更改知乎话题 编辑:程序博客网 时间:2024/05/01 14:34

首先不能再AJAX环境中用:Response.Write("<script>alert('提示');</script>");

但是ScriptManager类提供了两个方法:

public static void RegisterClientScriptBlock(Page page,Type type,string key,string script,bool addScriptTags)

public static void RegisterClientSctiptBlock(Control control,Type type,string key,string script,bool addScriptTags)

首先定义两个方法:

private void OpenDialogForPage(Page page,string message)

{

        ScriptManager.RegisterClientScriptBlock(page,typeof(Page),"key","alert('"+message+"')",true);

}

private void OpenDialogForButton(Button button,string message)

{

        ScriptManager.RegisterClientScriptBlock(button,typeof(Button),"key","alert('"+message+"')",true);

}

调用:OpenDialogForPage(Page,"页面弹出的提示框");

Button事件中:OpenDialogForPage((Button)sender,"按钮弹出的提示框");