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>");
}
}
}