The dynamicpopulate control is used to dynamically Replace the content of a control. Its content comes from a function call or web call.
Here is an example:
1) Create an ASP. NET Ajax-enabled web project in Vs and name it dynamicpopulateextender1.
2) Add a label in default. aspx to the trigger for dynamic operations. Then add four radio entries to display different call content.
CodeAs follows:
1 < ASP: Label ID = "Label1" Runat = "Server" Font-bold = "True" Text = "Time at the server" > </ ASP: Label > < BR />
2 < BR />
3 < Label For = "Radio1" > < Input ID = "Radio1" Name = "Time" Type = "Radio" Value = "G" Onclick = "Updatedatakey (this. Value )" /> Normal </ Label > < BR />
4 < BR />
5 < Label For = "Radio2" > < Input ID = "Radio2" Name = "Time" Type = "Radio" Value = "D" Onclick = "Updatedatakey (this. Value )" /> Short date </ Label > < BR />
6 < BR />
7 < Label For = "Radio3" > < Input ID = "Radio3" Name = "Time" Type = "Radio" Value = "D" Onclick = "Updatedatakey (this. Value )" /> Long date </ Label > < BR />
8 < BR />
9 < Label For = "Radio4" > < Input ID = "Radio4" Name = "Time" Type = "Radio" Value = "U" Onclick = "Updatedatakey (this. Value )" /> UTC time </ Label > < BR />
10 < BR />
3) Add a panel control on the page to display the content generated by different callbacks. Add a dynamicpopulateextender control to specify its attributes.
The Code is as follows:
1 < ASP: Panel ID = "Timepanel" Runat = "Server" Cssclass = "Dynamicpopulate_normal" Height = "50px" Width = "125px" >
2 </ ASP: Panel >
3 & Nbsp; </ Div >
4 < BR />
5 < C0: dynamicpopulateextender ID = "Dynamicpopulateextender1" Behaviorid = "Dp1" Updatingcssclass = "Dynamicpopulate_updating" Servicemethod = "Gethtml" Targetcontrolid = "Timepanel" Populatetriggercontrolid = "Label1" Runat = "Server" > </ C0: dynamicpopulateextender >
Attribute description:
Behaviorid: identifies the client behavior of the extended control.
Updatingcssclass: CSS style used for panel update.
Servicemethod: The called function method.
Targetcontrolid: controls that dynamically display different content.
Populatetriggercontrolid: the trigger specified when the content is dynamically displayed.
4) Add the gethtml function to the page. Code entry:
1 [System. Web. Services. webmethod ()]
2 [System. Web. Script. Services. scriptmethod ()]
3 Public Static String Gethtml ( String Contextkey)
4 {
5 System. Threading. thread. Sleep ( 250 );
6 String Value = (Contextkey = " U " ) ? Datetime. utcnow. tostring (): String. Format ( " {0: " + Contextkey + " } " , Datetime. Now );
7 Return Value;
8 }
5) Add a client script on the page to assign values to the dynamicpopulateextender when different input values are used.
The Code is as follows: 1 < Script Type = " Text/JavaScript " >
2 Function Updatedatakey (value)
3 {< br> 4 var behavior = $ find ('dp1 ');
5 If (behavior)
6 behavior. populate (value);
7 }
8 SYS. application. add_load ( Function () {Updatedatakey ('G ')} );
9 </ Script >
6) press Ctrl + F5 to view the final effect in the browser.