(3) 对于页面完成一个操作后,弹出一个对话框提示是否“操作成功”。 例: Response.Write("<script>...alert('删除成功!')</script>");
(4)允许 ASP.NET 服务器控件在 Page 中发出客户端脚本块: public virtual void RegisterStartupScript(string key,string script); 例: if(!this.IsStartupScriptRegistered("hello")) this.RegisterStartupScript("hello","<script>...alert('你好!')</script>");
弹出“确定”对话框: Response.Write("<Script Language=JavaScript>...alert('消息!');</Script>");
弹出“确定”对话框,点击后跳转页面: Response.Write("<Script Language=JavaScript>...alert('消息!');window.navigate('../index.aspx');</Script>");
弹出“确定”和“取消”对话框,点击“确定”后执行相关操作: 方法一:在Page_Load事件中,写入Button1.Attributes["onClick"]="javascript:return confirm('你确认要删除吗?');" ,然后在Button1_OnClick事件中写入您的执行代码。 方法二:直接在Button1_OnClik事件中写入 Response.Write("<Script Language=JavaScript>...if(confirm('你确认要删除吗?'))...{window.navigate('doDelete.aspx');} </Script>"); 方法二需要跳转到另一个页面执行操作,比方法一稍繁琐些,不过怎样用还看具体情况。
收集到的。用具类
using System;
/// <summary> /// Alert 的摘要说明。 /// </summary>
public class Alert { public static void ShowAlert(string message)
{
if(message==null)
message = ""; //ljj //2005-12-9
message=message.Replace(" ",""");
System.Web.HttpContext.Current.Response.Write("<script>...alert('"+message+"');</script>");
}
public static void ShowAlert(string message,string url) {
if(message==null)
message = "";
message = message.Replace(" ", """);
System.Web.HttpContext.Current.Response.Write("<script>...alert(""+message+"");location='"+url+"';</script>");
}
public static void ShowConfirmAlert(string message, string confirmurl, string cancelurl)
...{
if (message == null)
message = "";
message = message.Replace(" ", """);
System.Web.HttpContext.Current.Response.Write("<script Language=Javascript>if( confirm('" + message + "') ) {document.location.href='" + confirmurl + "'; }
else {
document.location.href='" + cancelurl + "' }</script>");
}
public static void ShowConfirmAlert(string message, string confirmurl)
...{
if (message == null)
message = "";
message = message.Replace(" ", """);
System.Web.HttpContext.Current.Response.Write("<script Language=Javascript>if( confirm('" + message + "') )
{document.location.href='" + confirmurl + "'; } else { window.history.back(); }</script>");
}
public static void Redirect(string url)
...{// // if(url==null||url.Length<1)
ShowAlert("重定向地址不能为空");
else
System.Web.HttpContext.Current.Response.Write("<script>location='"+url+"';</script>");
}
public static void SSOLoginRedirect(string url)
{
Redirect(url); //
if(url==null||url.Length<1) //
ShowAlert("重定向地址不能为空"); //
else //
System.Web.HttpContext.Current.Response.Write("<script>if(window.parent!=window) window.parent.location=window.location; location='"+url+"';</script>"); }
public static void ShowAlert(string message,string url,bool IsRedirect)
{
if(message==null)
message = "";
if(IsRedirect)
ShowAlert(message,url);
else
ShowAlert(message); }
}