http://sd.csdn.net/a/20110209/291379.html如何真正提高ASP.NET网站的性能
(1) 点击页面上的按钮,弹出一个对话框提示是“确定”还是“取消”操作,我们采用在按钮中添加属性来完成:
举例如下:
public System.Web.UI.WebControls.Button btnDelRow;
btnDelRow.Attributes.Add("onclick", "return confirm('确定要删吗?');");
(2) 点击页面上的按钮,弹出一个对话框提示是“确定”还是“取消”操作,选择“确定”或“取消”后跳转到相应的页面:
举例如下:
string strMsg, string strUrl_Yes, string strUrl_No;
Response.Write("<Script Language='JavaScript'>if ( window.confirm('"+strMsg+"')) { window.location.href='" + strUrl_Yes +
"' } else {window.location.href='"+ strUrl_No +"' };</script>");
(3) 对于页面完成一个操作后,弹出一个对话框提示是否“操作成功”。
举例如下:
Response.Write("<script>alert('删除成功!')</script>");
(4) 对于页面完成一个操作后,弹出一个对话框提示是否“操作成功”后跳转到某一个页面。
举例如下:
Response.Write("<script>alert('删除成功!');window.location.href ='www.cnblogs.com'</script>");
(5)允许 ASP.NET 服务器控件在 Page 中发出客户端脚本块:
public virtual void RegisterStartupScript(string key,string script);
举例如下:
if(!this.IsStartupScriptRegistered("hello"))
this.RegisterStartupScript("hello","<script>alert('你好!')</script>");
(6)下面是借鉴他人的一个弹出对话框调用类:
using System;
using System.Web;
namespace ShowMessage
{
/// <summary>
/// Msg 的摘要说明。
/// </summary>
public class ShowMessage
{
public ShowMessage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static void ShowMessage(string strMsg)
{
System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');</script>");
}
public static void ShowMessage(System.Web.UI.Page page, string strMsg)
{
page.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');</script>");
}
public static void ShowMessage( string strMsg, string Url)
{
System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');window.location.href ='"+Url+"'</script>");
}
public static void ShowMessage( System.Web.UI.Page page,string strMsg, string Url)
{
page.Response.Write("<Script Language='JavaScript'>window.alert('"+strMsg+"');window.location.href ='"+Url+"'</script>");
}
public static void ShowConfirm(string strMsg, string strUrl_Yes, string strUrl_No)
{
System.Web.HttpContext.Current.Response.Write("<Script Language='JavaScript'>if ( window.confirm('"+strMsg+"')) { window.location.href='" + strUrl_Yes +
"' } else {window.location.href='"+ strUrl_No +"' };</script>");
}
}
}
/*摘文*/
允许 ASP.NET 服务器控件在 Page 中发出客户端脚本块: public virtual void RegisterStartupScript(string key,string script); 例: if(!this.IsStartupScriptRegistered("hello")) this.RegisterStartupScript("hello","<script>...alert('你好!')</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); }}