We're in. NET program in the development process, often need to interact with the user information, for example, the success of a certain operation, "OK" or "Cancel", and choose "OK" or "Cancel" after the need to jump to a page, and so on, the following is my common use of dialog box summary, I hope to help you, At the same time also welcome everyone to add.
(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 (' Delete succeeded! ') ("<script>alert") </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 (' Delete success! ') ("<script>alert"); window.location.href = ' www.cnblogs.com ' </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:
if (!this. isstartupscriptregistered ("Hello"))
This. RegisterStartupScript ("Hello", "<script>alert") </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>
A summary 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 ('" +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>");
}
}
}