The following is my common use of dialog box summary, I hope to help you, but also welcome everyone to add.
We're in. NET program in the development process, often need to interact with the user, such as the success of an operation, "OK" or "Cancel", and choose "OK" or "Cancel" after the need to jump to a page, etc.
(1) Click on the button on the page, pop-up a dialog box prompts "OK" or "Cancel" operation, we use the button to add properties to complete:
examples are as follows:
Copy Code code as follows:
public System.Web.UI.WebControls.Button Btndelrow;
btnDelRow.Attributes.Add ("onclick", "return confirm (ok to delete?);");
(2) Click on the button on the page, pop-up a dialog box prompts "OK" or "Cancel" operation, select "OK" or "Cancel" to jump to the appropriate page:
examples are as follows:
Copy Code code 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 a page completes an operation, a pop-up dialog box prompts whether "successful operation."
examples are as follows:
Copy Code code as follows:
Response.Write ("<script>alert" (delete succeeded!) </script> ");
(4) for a page to complete an operation, a pop-up dialog box prompts whether the "successful operation" after the jump to a page.
examples are as follows:
Copy Code code as follows:
Response.Write ("<script>alert (delete succeeded!)" Window.location.href =www.jb51.net</script> ");
(5) Allow ASP.net server controls to emit client script blocks in Page:
Copy Code code as follows:
public virtual void RegisterStartupScript (string key,string script);
Examples are as follows:
Copy Code code as follows:
if (!this. isstartupscriptregistered ("Hello"))
this. RegisterStartupScript ("Hello", "<script>alert" (Hello!) </script> ");
(6) The following is my collation of a pop-up dialog box call class:
Copy Code code as follows:
using System;
using System.Web;
namespace ShowMessage
{
///<summary>
Abstract description of
///MSG.
///</summary>
public class ShowMessage
{
public showmessage ()
{
//
//TODO: Add constructor logic here
//
}
public static void ShowMessage (string strMsg)
{
System.Web.HttpContext.Current.Response.Write ("<script language=javascript>window.alert (" + str MSG + ");</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>");
}
}
}