The updatepanel control is also one of the most commonly used controls in Ajax. The updatepanel control is used to partially update the content on the webpage. The content to be partially updated on the webpage must be placed in the updatepanel control, it must be used with the last scriptmanager control. Now let's look at the attributes of updatepanel.
Important attributes of updatepanel are as follows:
Attribute |
Description |
Childrenastriggers |
When the updatemode attribute is conditional, whether the asynchronous return of the child control in updatepanel triggers updatepanle update. |
Rendermode |
Indicates the final HTML element of updatepanel. Block (default) indicates <div>, inline indicates <span> |
Updatemode |
Updatepanel update mode. There are two options: Always and conditional. Always: No matter whether there is a trigger, other controls will update the updatepanel. Conditional indicates that only the trigger of the current updatepanel is available, or the asynchronous or whole-page delivery triggered by the control in the current updatepanel is set to true, or the updatepanel will be updated only when the server calls the update () method. |
Childrenastriggers: If the updatemode attribute is conditional, whether the asynchronous delivery of the child control in updatepanel triggers updatepanle updates.
Rendermode: indicates the HTML element finally rendered by updatepanel. Block (default) indicates <div>, inline indicates <span>, and updatepanel indicates the final HTML element. Updatemode: indicates the update mode of updatepanel. There are two options: Always and conditional. Always: No matter whether there is a trigger, other controls will update the updatepanel. Conditional indicates that only the trigger of the current updatepanel is available, or the asynchronous or whole-page delivery triggered by the control in the current updatepanel is set to true, or the updatepanel will be updated only when the server calls the update () method.
Contente template: used to define the content of updatepanel
Triggers: asyncpostbacktrigger and postbacktrigger
Asyncpostbacktrigge is used to specify a server-side control and use the triggered server-side event as the asynchronous update trigger of the updatepanel. The attributes that need to be set include the control ID and the events of the server-side control;
Postbacktrigger is used to specify a Server Control in updatepanel. The callback triggered by postbacktrigger is not asynchronous, but is still a traditional whole-page delivery.
Now let's make a simple example:
<Span style = "font-size: 18px;"> <% @ page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. CS "inherits =" _ default "%> <! Doctype HTML public "-// W3C // dtd xhtml 1.1 // en" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
It contains a triggers, in which the first attribute asyncpostbacktrigger specifies that button1 implements asynchronous update, while postbacktrigger
Specify button2 to update the entire page.
. CS code:
<Span style = "font-size: 18px;"> protected void button1_click1 (Object sender, eventargs e) {sqlconnection conn = new sqlconnection ("Server = .; uid = sa; Pwd =; database = pubs "); string sql1 =" select top 5 au_lname from authors "; sqldataadapter myadapter = new sqldataadapter (sql1, Conn ); dataset DS = new dataset (); myadapter. fill (DS, "bieming"); // dataset from the web service. You can use either of them here. This. gridview1.datasource = Ds. tables ["bieming"]. defaultview; this. gridview1.databind (); // data binding} protected void button2_click (Object sender, eventargs e) {This. label1.text = "11111" ;}</span>
Updatepanel is a very good control. With this control, you can avoid writing JavaScript code and do not change the Ajax mechanism. You can say that you will use Ajax!