Extend ASP.NET AJAX Client-Side Function - The Server-Side Way
page 9 of 11
by Xianzhong Zhu
Average Rating: 
Views (Total / Last 10 Days): 46770/ 70

Using a Custom ASP.NET AJAX Control in an ASP.NET Page

First, open menu "File->Add…," click "New Website…" and select "ASP.NET AJAX-based Web Site" template to create a sample website named AJAXServMenu.

Second, right-click the website and add reference to the above newly-generated assembly.

Third, to use the server control AJAXServMenuCtrl in page "Default.aspx," we have to first register the control in the page by using the following Register directive:

<%@ Register Assembly="AJAXServMenuLib" Namespace="AJAXServMenuLib"  TagPrefix="ajax" %>

This directive references the assembly name (AJAXServMenuLib), the namespace that the control resides in (AJAXServMenuLib), as well as the tag prefix (ajax) that should be used to define the control in this page. Once registered, this control can be used in the page just the same as any other ASP.NET server control. What we merely need to do is define the tag prefix and class name followed by all of the necessary properties in the Register directive. In this case, the related code is shown below.

Listing 11

<ajax:AJAXServMenuCtrl ID="divAjaxMenu" runat="server"  MenuTitle="Topics"
MenuTopCssClass="menutop" MenuListCssClass="menulist" 
ServicePath="MenuService.asmx" ServiceMethod="GetMenuData" Width="500px" />

Once the page is called by an end user through a browser, the necessary client-side script code used by control AJAXServMenuCtrl will automatically be added to the rendered output by the ScriptManager control.

Now, just press F5 and watch what happens. Figure 5 corresponds to one of the run-time snapshots.

Figure 5 - One of the run-time snapshots for Sample 2

Author's Note: Here, I omit the analysis of the generated HTML code on the browser, but I highly recommend readers to examine it themselves to make clearer the mechanisms behind the scenes.

View Entire Article

User Comments

No comments posted yet.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-18 4:25:05 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search