. NET Pop-up dialog box method rollup

Source: Internet
Author: User
Tags httpcontext
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>");


        }        


    }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.