[ASP. NET] pop-up message box

Source: Internet
Author: User

 

 

Study how to pop up the message box. The method of C # pop-up message box in the background cannot be found. Only JS scripts can be used to pack the pop-up results. Let's see how to pop up the message box on the page.

 

* ** JS pop-up message box ***

 

Syntax: <script language = JavaScript>

Alert ('');

</SCRIPT>

 

Description: Alert () is a window object method in Javascript. A warning box with a message and a confirmation button is displayed. It can be called in The onclick event of the control.

 

* ** JS pop-up message box ***

 

Default. aspx

 

HTML code
  1. <HTML xmlns = "http://www.w3.org/1999/xhtml">
  2. <Head runat = "server">
  3. <Title> Page Object-default page </title>
  4. </Head>
  5. <Body bgcolor = "# ffff99">
  6. <Form ID = "form1" runat = "server">
  7. <Div>
  8. <Asp: button id = "button1" runat = "server" onclick = "button#click"
  9. TEXT = "response. Write"/>
  10. <Br/>
  11. <Br/>
  12. <Asp: button id = "button2" runat = "server" onclick = "button2_click"
  13. TEXT = "Page. clientscript. registerstartupscript" width = "244px"/>
  14. </Div>
  15. </Form>
  16. </Body>
  17. </Html>
<HTML xmlns = "http://www.w3.org/1999/xhtml"> 

 

 

Default. aspx. CS

 

C # code
  1. Public partial class _ default: system. Web. UI. Page
  2. {
  3. Protected void button#click (Object sender, eventargs E)
  4. {
  5. Response. Write ("<script language = JavaScript> alert ('this is response. Write () '); </SCRIPT> ");
  6. }
  7. Protected void button2_click (Object sender, eventargs E)
  8. {
  9. Page. clientscript. registerstartupscript (page. GetType (), "message ",
  10. "<Script language = JavaScript> alert ('this is page. clientscript. registerstartupscript () '); </SCRIPT> ");
  11. // Page. registerstartupscript ("message ",
  12. // "<Script language = JavaScript> alert ('this is page. registerstartupscript () '); </SCRIPT> ");
  13. }
  14. }
Public partial class _ default: system. web. UI. page {protected void button#click (Object sender, eventargs e) {response. write ("<script language = JavaScript> alert ('This is response. write () '); </SCRIPT> ");} protected void button2_click (Object sender, eventargs e) {page. clientscript. registerstartupscript (page. getType (), "message", "<script language = JavaScript> alert ('This is page. clientscript. registerstartupscript () '); </SCRIPT> "); // page. registerstartupscript ("message", // "<script language = JavaScript> alert ('This is page. registerstartupscript () '); </SCRIPT> ");}}

Okay. Let me talk about the running mechanism. Response. Write () and page. clientscript. registerstartupscript () can both execute the script language. The difference is that when the former is executed, the page will be displayed in white

(The background changes to white) and the latter does not have a white screen, so the latter has a better user experience. The latter also has a sibling page. clientscript.

Registerclientscriptblock (). They can all execute scripts. What are their differences? They are executed differently on the page. The registerstartupscript method embeds JavaScript at the bottom of the ASP. NET page, just before the close element </form>. The registerclientscriptblock method is to embed Javascript into the page to enable the element.
After <form>, when the script is executed to search for a control, the execution order shows that the business trip is different. The output result of the preceding example is as follows:

Response. Write () method, white screen --

The page. clientscript. registerstartupscript () method is displayed normally. (The background color is beige)

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.