Several pop ups in ASP.NET suggest basic implementation methods

  • 2020-05-30 19:50:26
  • OfStack

We in. NET program development process, often need to interact with the user information, such as performing an action is successful, "ok" or "cancel", and select the "ok" or "cancel" whether need to jump to a page, the following is my summary over the use of common dialog box, hope to be of help, at the same time also welcome you to add.

(1) click the button on the page, and a dialog box will pop up, indicating whether to "confirm" or "cancel" the operation. We will add properties in the button to complete:
Examples are as follows:
 
public System.Web.UI.WebControls.Button btnDelRow; 
btnDelRow.Attributes.Add("onclick", "return confirm(' Are you sure you want to delete it ?');"); 

(2) click the button on the page, and a dialog box will pop up, indicating whether to "confirm" or "cancel" the operation. Select "confirm" or "cancel" and jump to the corresponding page:
Examples are as follows:
 
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) after completing one operation on the page, a dialog box will pop up to indicate whether the operation was successful.
Examples are as follows:
 
Response.Write("<script>alert(' Delete the success !')</script>"); 

(4) after completing one operation on the page, a dialog box will pop up to prompt whether the operation is successful and jump to a certain page.
Examples are as follows:
 
Response.Write("<script>alert(' Delete the success !');window.location.href ='www.cnblogs.com'</script>"); 

(5) allow ASP.NET server control to emit client script blocks in Page:
 
public virtual void RegisterStartupScript(string key,string script); 

Examples are as follows:
if(!this.IsStartupScriptRegistered("hello"))
this.RegisterStartupScript("hello"," < script > alert (' hello! ') < /script > ");
(6) the following is a popup dialog box calling class sorted by me:
 
using System; 
using System.Web; 
namespace ShowMessage 
{ 
/// <summary> 
/// Msg  A summary of.  
/// </summary> 
public class ShowMessage 
{ 
public ShowMessage() 
{ 
// 
// TODO:  Add the constructor logic here  
// 
} 
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>"); 
} 
} 
} 

Related articles: