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
- <HTML xmlns = "http://www.w3.org/1999/xhtml">
- <Head runat = "server">
- <Title> Page Object-default page </title>
- </Head>
- <Body bgcolor = "# ffff99">
- <Form ID = "form1" runat = "server">
- <Div>
- <Asp: button id = "button1" runat = "server" onclick = "button#click"
- TEXT = "response. Write"/>
- <Br/>
- <Br/>
- <Asp: button id = "button2" runat = "server" onclick = "button2_click"
- TEXT = "Page. clientscript. registerstartupscript" width = "244px"/>
- </Div>
- </Form>
- </Body>
- </Html>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
Default. aspx. CS
C # code
- 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> ");
- }
- }
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)