ASP. NET dialog box

Source: Internet
Author: User
This is often the case during recent project development. When a user clicks a button on the page, a window pops up. This window may be a standard dialog box or a new page. At the beginning, I didn't know how to implement this function. According to my previous programming habits, I think there should be a method similar to showmessage. However, unfortunately, this method does not exist on the web. By checking the information on the Internet, it is found that the general practice is to write the following in the onclick event of the button: Code : Private   Void Button#click ( Object Sender, system. eventargs E)
{
String Strscript =   " <Script language = JavaScript> \ n " ;
Strscript + =   " Window. Alert ( "   +   " \ " Hello \ ""   +   " ); " ;
Strscript + =   "" ;
Response. Write (strscript );
}

The effect of the above Code is that when you click the button1 button, a dialog box will pop up. In this way, a Javascript script file is embedded in your. CS file. However, I think it may be uncomfortable to see such code, so many "" are easy to faint! If you need to bring up a page and pass parameters, the code you write will feel dizzy!
Later, I was wondering if I could put all the scripts in the. aspx file and directly reference the function name in. CS. It turns out that this is acceptable. See the following implementation method:
1. Add this code before aspx < Script Language = " JScript " >  
Function Showmessagebox ()
{
Window. Alert ( " Hello " );
}

2. Add the following code to the page_load event of the CS file: Private   Void Page_load ( Object Sender, system. eventargs E)
{
// Place user code here to initialize the page
This . Button1.attributes. Add ( " Onclick " , " Javascript: showmessagebox (); " );
}

3. Now, when you click the button1 button on the page, the result is similar to the previous method, but the entire system code looks quite comfortable.

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.