We are. in the development process of the net program, it is often necessary to interact with the user, for example, whether a certain operation is successful, "OK" or "cancel ", and whether to jump to a page after "OK" or "cancel" is selected. The following is a summary of my use of frequently-used dialog boxes. I hope this will help you. You are also welcome to add this article.
(1) click the button on the page and a dialog box is displayed, prompting whether to "OK" or "cancel". We can add attributes to the button to complete the operation:
Example:
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 to bring up a dialog box prompting "OK" or "cancel". Select "OK" or "cancel" to go to the corresponding page:
Example:
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 an operation on the page, a dialog box is displayed, prompting whether the operation is successful ".
Example:
Response. Write ("<SCRIPT> alert (" deleted successfully! ") </SCRIPT> ");
(4) after you complete an operation on the page, a dialog box is displayed, prompting whether the operation is successful.
Example:
Response. Write ("<SCRIPT> alert (" deleted successfully! "); Window. Location. href =" www.cnblogs.com "</SCRIPT> ");
(5) Allow ASP. NET Server controls to issue client script blocks in the page:
Public Virtual void registerstartupscript (string key, string script );
Example:
If (! This. isstartupscriptregistered ("hello "))
This. registerstartupscript ("hello", "<SCRIPT> alert (" Hello! ") </SCRIPT> ");
(6) The following is a pop-up dialog box call class compiled by myself:
Using system;
Using system. Web;
Namespace showmessage
{
/// <Summary>
/// Summary of MSG.
/// </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, 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, 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> ");
}
}
}