Ajax Learning Record 7 in Asp.net: updatepanel updated with JavaScript

Source: Internet
Author: User

In addition to adding controlid to the triggers of updatepanel, The updatepanel refresh function also provides the method Update () function used in the previous article. I learned another method in this blog, we use _ dopostback () (two underscores) in JavaScript to achieve the page effect. When we click button1, the label in updatepanel1 gets the system time.

Note: the front-end function _ dopostback is mainly used for the Web Control PostBack. It sends control information to the server through the two hidden controls _ eventtraget ,__ eventargument.

Page Layout: 1. Drag and Drop scriptmanager1.

2. Put updatepanel1 and set updatemode = conditional of updatepanel1.

3. In updatepanel1, add label1.

4. Put an HTML button1.

PageSource codeAs follows: When you click button1, the _ dopostback function is triggered, causing the page to refresh.

Note _ dopostback usage
1 <% @ Page Language = " C # " Autoeventwireup = " True " Codefile = " Default. aspx. CS " Inherits = " _ Default "   %>
2 <! Doctype HTML public " -// W3C // dtd xhtml 1.0 transitional // en "   " Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
3 < HTML xmlns = " Http://www.w3.org/1999/xhtml " >
4 < Head runat = " Server " >
5 < Title > No title page </ Title >
6 </ Head >
7 < Body >
8 < Form ID = " Form1 " Runat = " Server " >
9 < Div >
10 < ASP: scriptmanager ID = " Scriptmanager1 " Runat = " Server " >
11
12 </ ASP: scriptmanager >
13 < Script Language = " Javascript " >
14 Function comfirmrefresh ()
15 {
16 If (Confirm ( " Are you sure you want to refresh? " ))
17 {< br> 18 // the first parameter is the ID of the control you want to submit to the server, the second parameter is the event parameter
19 _ dopostback ( " updatepanel1 " , " refresh " );
20 }
21 }
22 </ Script >
23 < Input ID = " Button1 " Type = " Button " Value = " Button " Onclick = " Comfirmrefresh () "   />
24 < ASP: updatepanel ID = " Updatepanel1 " Runat = " Server " Updatemode = " Conditional " >
25 < Contenttemplate >
26 < ASP: Label ID = " Label1 " Runat = " Server " Text = " Label " > </ ASP: Label >
27 </ Contenttemplate >
28 </ ASP: updatepanel >
29 </ Div >
30 </ Form >
31 </ Body >
32 </ Html >
33

CSCodeAs follows:

 

Page loading is used to determine whether the page is partially refreshed
1 Public   Partial   Class _ Default: system. Web. UI. Page
2 {
3 Protected   Void Page_load ( Object Sender, eventargs E)
4 { // When the current value of scriptmanager1 sending back is asyncpostback and the control that causes the asynchronous sending back event of scriptmanager1 is updatepanel1.
5 If (Scriptmanager1.isinasyncpostback && Scriptmanager1.asyncpostbacksourceelementid =   " Updatepanel1 " )
6 // Label1 obtains the current system time.
7 Label1.text = Datetime. Now. tostring ();
8 }
9 }
10

 

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.