Previous | Home | Next |
DynamicPopulate is a simple extender that replaces the contents of a control with the result of a web service or page method call.The DynamicPopulate control in the ASP.NET AJAX Control Toolkit calls a web service (or page method) and fills the resulting value into a target control on the page, without a page refresh.
DynamicPopulateExtender property:
TargetControlID: It represnt id of the button.
ClearContentsDuringUpdate: It is bydefult true for clear the HTML contents when new updation starts.
ServicePath: The URL of the web service to call
ServiceMethod: The name of the method to call on the page or web service
UpdatingCssClass: The CSS class to apply to the target during asynchronous calls.
CustomScript: Its used for calling a Web or Page method.
ContextKey: An arbitrary string value to be passed to the web method
CacheDynamicResults: Whether the results of the dynamic population should be cached and not fetched again after the first load.
Step 1: Start -> All Programs -> Visual Studio 2005 or Visual Studio 2008
Step 2: Now go to File Menu -> New -> Web Site
Step 3: Under Visual Studio Installed Template-> Choose ASP.NET WEB SITE -> Choose File System< from the location combo box -> Set the path by the browse button - > Choose the language from the Language ComboBox (Visual C# ,Visual Basic , J #)
Choose Visual C#
Step 4: Click on the OK Button.
Step 5: Now drag some controls under the AJAX Extensions.
First control you are going to drag and drop on the page is - Script Manager.
After that .
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <script runat="server"> [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod] public String operation(string s) { return Convert.ToString( "You Selected Pizza " + s); } </script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type = "text/javascript"> function UpdatePizza(chkcount) { var behavior = $find('dp1'); var value = ''; for (i = 0; i < chkcount; i++) { if (document.forms[0].chknumber[i].checked == true) value = ' With ' + document.forms[0].chknumber[i].value + ','; } if (behavior) { behavior.populate(value); } } Sys.Application.add_load(function(){Updatenumber(3);}); </script> <br /> <label for="Chk1"><input id="Chk1" type="checkbox" name="chknumber" value="100" onclick="Updatenumber(3);" />100</label><br /> <label for="Chk2"><input id="Chk2" type="checkbox" name="chknumber" value="200" onclick="Updatenumber(3);" />200</label><br /> <label for="Chk3"><input id="Chk3" type="checkbox" name="chknumber" value="300" onclick="Updatenumber(3);" />300</label><br /> <br /> <asp:Panel ID="Panel1" runat="server"> </asp:Panel> <cc1:DynamicPopulateExtender ID="DynamicPopulateExtender1" runat="server" TargetControlID="Panel1" BehaviorID="dp1" ServiceMethod="operation"> </cc1:DynamicPopulateExtender> </form> </body> </html>
Step 6: Now run your web site by Ctrl + F5
Step 7: Output is
Previous | Home | Next |