Create a custom Web control with ASP.net 2.0

Source: Internet
Author: User
Tags date emit empty html tags new features string format tagname visual studio
asp.net|web| Create | Controls Jayesh Patel, Bryan Acker, Robert McGovern
Infusion Development
Apply to:
Microsoft asp.net 2.0
Microsoft Visual Studio 2005

Absrtact: The new adaptive rendering model in ASP.net 2.0 provides many new options for control writers. This article shows how these options make it easier to create ASP.net custom controls than before.



Content of this page
Brief introduction
Adaptive Rendering Model
Creating a custom server control
Tagkey
Using custom controls
Creating a composite server control
Creating a composite control
Adding control behavior
callback Example
Using the designer
Summary

Brief introduction
WEB Development has undergone a lengthy process from the use of basic text editors to authoring markup pages. Currently, the Integrated development Environment (IDE) provides a graphical representation of almost every aspect of the development process. In addition, a variety of descriptive programming techniques are implemented to improve efficiency and reduce the likelihood of errors. The control architectures in Visual Studio 2005 and ASP.net 2.0 follow these programming trends and provide a reliable, extensible environment designed to allow developers to create controls that can be configured in a descriptive manner.

In addition, the new adaptive rendering model in asp.net reduces the need to write controls that specifically identify their target browsers. In other words, a control developer can focus on designing controls, and let the asp.net framework be responsible for converting controls and rendering them for different types of browsers and devices.

Although ASP.net 2.0 provides incremental improvements in the control design process, the actual control rendering model has been completely changed. As a custom control developer, you'll see several new options for leveraging asp.net. Most importantly, you'll find that you can accomplish the same task by writing fewer code.

In asp.net 2.0, there are many ways to create a custom server control, each of which has its advantages and limitations. This article discusses details related to the creation and configuration of custom controls. Code samples and architectural concepts require you to have a moderate level of understanding of the C # programming language.


Adaptive Rendering Model
In ASP.net 1.x, custom control developers must design each server control so that it can recognize different browser types and emit the correct output. The ASP.net 1.x control framework provides several features to make this task simpler, but developers must still write switches based on the type of browser, develop the appropriate HTML, and then test the controls for different types of browsers. Additionally, if the developer wants the control to appear on the mobile device, he must create a new control that is different from the one used on the normal Web browser.

ASP.net 2.0 simplifies the browser detection and rendering process through the new adaptive rendering model. The adaptive rendering model introduced in ASP.net 2.0 is designed to support many different devices that can use tag formats, including HTML, WML, XHTML, or CHMTL.

Adaptive Rendering Model architecture
Each control can be linked to an adapter that modifies the behavior and markup of the control against a specific target device. For example, an HTML adapter generates ASP.net controls as standard HTML and DHTML for use by ordinary Web browsers. On the other hand, the WML adapter converts the same control into a wireless markup language for use by a cellular phone or other mobile device.



Figure 1. Control-Adapter Life cycle

The figure above illustrates a one-to-one mapping between the control method and the adapter method. If there is an adapter (if the control's Adapter property is not empty), execution is transmitted between the control and the adapter method, as shown in the figure above. In the build phase, both the control object or the adapter object can generate output (typically, they do not produce the output at the same time). Typically, if there is an adapter, the implementation of the adapter overrides the control's implementation. In ASP.net 2.0, the adaptive rendering model applies to all ASP.net controls (not just mobile controls), and allows ASP.net 2.0 to support a unified control architecture.

Practical significance
The practical meaning of adaptive rendering model has two main aspects. First, as a developer, you can design the control one time and expect it to be available on any type of device or browser that has an adapter. Second, you can use a wide range of Microsoft tests on your common adapters to reduce specific tests for your own browsers.

The adaptive rendering model also provides the opportunity for ASP.net 2.0 to add additional services to the control generation process. Because you have an adapter model, you can:

• Use filters to change the appearance of the control, depending on the type of target.

• Use templates to change the layout of the entire page, depending on the type of target.

• Depending on the browser's control of rendering on the browser, it is not necessary to rely on the uplevel/downlevel determination of ASP.net 1.x.


In this article, we will focus on the application aspects of creating custom controls. However, keep in mind that the adaptive rendering model is the new underlying framework.


Creating a custom server control
Visual Studio 2005 provides a number of useful tools to develop custom server controls. To illustrate some features, we'll create a MailLink control that exposes two properties: Email and Text. The control generates the necessary HTML to wrap the supplied Text in the mailto: link tag.

Create a project
In Visual Studio 2005, we created a new Web control Library project by selecting the appropriate icon in the New Project Wizard:



Figure 2. New Project Wizard in Visual Studio 2005

The project is created using the default custom control class implementation. For our example, we rename the default file to MailLink.cs.

Note: When you rename the file in Solution Explorer, Visual Studio 2005 automatically updates the class name.

The source code for MailLink is built on the default template generated by the Project Wizard. The MailLink class is automatically derived from the WebControl base class.

public class Maillink:webcontrol {

The WebControl class provides a default implementation method that can be easily overridden to provide detailed instructions for our controls.

Add properties
In the MailLink example, we need to add the Email and Text properties. To properly configure these properties, we must not only write code, but also assign several attributes.

[Bindable (True),
Category ("appearance"),
DefaultValue (""),
Description ("The e-mail address.")]

Public virtual string Email {
get {
string s = (string) viewstate["Email"];
return (s = = null)? String.empty:s;
}
set {
viewstate["Email"] = value;
}
}

Attributes, in bold, define how the new control will interact with the designer (Visual Studio). The attributes of the Email attribute tell Visual Studio how to handle attributes during the design process:

The Bindable-email property can be bound to a data source. You can link an Email field to a database, an XML file, or any other DataSet. This attribute forces Visual Studio to display an Email attribute in the list of bindable properties for the control.

The Appearance-email property is displayed in the Properties view under the Appearance category. You can select any category you want, including the default category: appearance, accessibility, Behavior, Data, Layout, or Misc. As long as the user chooses the attribute's class organization method, the Email attribute will be displayed under appearance.

The Defaultvalue-email property has an empty default value. Although null values are meaningful for Email fields, they may not be appropriate for other properties that you add to the control. When users place your controls on their Web pages, choosing the appropriate default value frees users from countless clicks.

The description-Property description appears under the list of controls and may also appear as a ToolTip. The email attribute will have the e-mail address description.

localizable-It notifies the ASP.net 2.0 Framework by sending a signal the control includes text properties that can be configured for different languages or locations.


You can use the various features in the System.ComponentModel namespace to further improve the appearance and behavior of any particular property. We will describe in more detail how to modify the behavior of a property or control in the Use designer section of this article.

Next, we need to add the Text property. The Text property is slightly different from the Email attribute because we want to display text as part of the HTML emitted by the MailLink control. To do this, we need to add a new attribute from the System.Web.UI namespace.

[Bindable (True),
Category ("appearance"),
DefaultValue (""),
Description ("The text to display on the link."),
Localizable (true),
PersistenceMode (Persistencemode.innerdefaultproperty)]
Public virtual string Text {
get {
string s = (string) viewstate["Text"];
return (s = = null)? String.empty:s;
}
Set {
viewstate["Text"] = value;
}
}

The PersistenceMode (Persistencemode.innerdefaultproperty) attribute of the Text property (bold code) specifies that the designer should serialize the property as an internal content within the control tag. The attribute also declares that Text is the default property of the control. When the user uses this control in Visual Studio, the Text property will automatically appear on the graphics designer as the inner text of the control, and if the user clicks the control and tries to change the displayed text, the Text property will automatically change.

On the other hand, attributes applied to attributes affect how users interact with the controls during design time. During the run, these attributes are ignored by the ASP.net runtime.

Comments about ViewState
Note that both the GET and Set methods for both properties take advantage of the ViewState object. The ViewState object is a helper object built into the WebControl class. From a development perspective, ViewState can be considered as a collection class for storing any attributes we want to keep in the postback process. In fact, ViewState encapsulates all the code and logic needed to determine how to execute persistence (using cookies, sessions, and so on).

Building controls
After you define a control property, the next step is to design the actual response that will be emitted by the control. In the MailLink example, we want to design controls to generate basic HTML markup.


Tagkey
The default implementation of the WebControl generates a token. Our MailLink control overrides the default implementation by providing its own implementation for the Tagkey property. The Tagkey property defines the outermost markup that will encapsulate the content of the control.

Fortunately, we can use the HtmlTextWriterTag enumeration to indicate the link tag without actually writing HTML text. This enumeration method is used for the most common HTML tags.

protected override HtmlTextWriterTag Tagkey {
get {
return htmltextwritertag.a;
}
}

If you need to generate a tag that is not part of the HtmlTextWriterTag enumeration, you must overwrite the Webcontrol.tagname property, not the Tagkey property. The TagName property returns the actual HTML tag string generated by the control. The default WebControl implementation of the TagName invokes only the Tagkey and extracts the correct HTML in a perfect extraction manner.

Attributestorender
After defining the base tag, the next step is to assign the various attributes that we want to add to the tag. Our MailLink control overrides the Addattibutestorender method to add the appropriate markup for the "mailto" tag.

protected override void AddAttributesToRender (
HtmlTextWriter writer) {
Base. AddAttributesToRender (writer);
Writer. AddAttribute (Htmltextwriterattribute.href,
"mailto:" + Email);
}

The Addatributetorender () call to the base class is invoked to ensure that other styles and attributes are generated correctly. If we ignore this basic call, we may lose the master page design, filter, or other functionality built into all WEB controls.

RenderContents
Finally, because the methods and properties of the required WebControl class have been overridden, you can use the RenderContents method to write the text. For security reasons, MailLink uses the Htmltextwriter.writeencodedtext method to write HTML-encoded output. HTML encoding safely converts potentially dangerous characters into a more secure representation.

protected override void RenderContents (
HtmlTextWriter writer) {
if (Text = = String.Empty) {
Text = Email;
}
Writer. Writeencodedtext (Text);
}

Please note that we only generate the Text property. If the Text property is empty, we will populate it with the Email attribute. Keep in mind that the Text property is intended to be used as the inner text of the control's markup. This type of control requires at least one text that can be displayed (so that the user clicks). If we try to generate an empty string, we lose the expected functionality of the link tag.

How is it generated?
The Render () method basically controls the entire output of the WebControl. By default, the Render () method actually calls RenderBeginTag (), RenderContents (), and RenderEndTag () in turn. Although the call structure does not change in ASP.net 1.x, the effect of modifying these calls has changed due to the rendering model.

You can overwrite the Render () method to emit any content you want. In other words, you may have skipped overwriting the Tagkey property, the Attributestorender property, and the RenderContents () method, and only Render () write "text." However, this practice can seriously affect adaptive rendering. If you override Render () to emit the final output directly, you bypass most of the adaptive rendering features built into the WebControl class.

The adaptive rendering model and the various adapters are used to intercept calls to various markup methods and to transform the output of a particular device. In a particular example of MailLink, almost all markup languages support the same syntax for linking. However, other tags typically have distinct transformations in different markup languages. If we use Render () for such a tag, our control will only be used on some browsers, and the adapter cannot change the behavior. By designing controls to use adaptive elements instead of using Render (), you can give the ASP.net framework an opportunity to provide rendering services on the browser based on the browser.


Using custom controls
Custom controls can be included in the WEB application in many ways. The standard approach is to compile the custom control into an assembly, and then add a reference to the assembly in all WEB applications that use the control.

Using Emaillink
In order to use the Emaillink control, you need:

1.
Compile the MyControls project into an assembly.



Figure 3. Compiling MyControls namespaces that contain Emaillink controls

2.
Adds a reference to the compiled assembly in the new Web project.



Figure 4. Compiling the application and adding a reference


After the reference is correctly added, the custom control should appear under "MyControls components" in the toolbox.



Figure 5. Emaillink in the Toolbox

All components in the MyControls assembly use the default gear icon because we never set a specific icon on each control. Setting an icon is as simple as resizing an icon property on the control class.

Controls on a page
After you add a reference to the assembly that contains the control, you can drag the MailLink control to the designer surface and use it as you would any other ASP.net server control.



Figure 6. MailLink Custom Controls

Figure 6 shows the designer view of the MailLink control. Note that the Properties window exposes the expected Email and Text elements that can be used to configure the control. By compiling a custom control into a reusable assembly, the MailLink control can be reused by many WEB applications.

Creating a composite server control
Reliable controls such as Login and GridView are made up of a number of basic controls. In ASP.net 1.x, you must develop a composite control by adding nested tags and elements to your custom control through hard work. In asp.net 2.0, you can build complex composite controls by extending the System.Web.UI.WebControls.CompositeControl class. The CompositeControl class provides the necessary framework for merging the output of multiple controls into a single unified control.

Managing composite controls is a little more difficult than managing basic custom controls, because composite controls require information about custom layouts. Composite controls delegate their rendering and event-handling tasks to the constituent control. All associated adapter classes for the subassembly are also automatically applied. This way, if you have the appropriate adapter, the composite control will render correctly on any target browser type or device.

Creating a composite control
The initial process of creating a composite control is similar to the initial process of creating a custom server control. However, there are more steps involved in this process. In the following example, we will create a simple composite agecollector control consisting of a Label and a TextBox designed to collect information about birthdays.

The composite control class should start by inheriting from the CompositeControl.

public class Agecollector:compositecontrol
{
}

Defining attributes
For our simple controls, we have to create attributes for tags (Prompt) and text boxes (dateOfBirth).

[Bindable (True), Category ("appearance"),
DefaultValue ("Please enter your date of birth:"),
Description ("Text to Prompt user with.")
Localizable (true)]
Public virtual String Prompt {
Get
{
string s = (string) viewstate["Prompt"];
return (s = = null)? String.empty:s;
}
set {
viewstate["Prompt"] = value;
}
}

Once again, we use attributes to provide a description and default value for the attribute. We chose to have the hint localized so that the control can be used at any time in applications that require internationalization. The actual hint can be bound to a resource file that contains language-specific text.

You must also define the dateOfBirth property. Instead of using String, however, we use DateTime data types to store dates correctly.

[Bindable (True), Category ("appearance"),
DefaultValue (""),
Description ("Date of birth Input area")]
Public virtual DateTime dateOfBirth {
Get
{
Bject o = viewstate["dateOfBirth"];
return (o = null)? DateTime.Now: (DateTime) o;
}
set {
viewstate["dateOfBirth"] = value;
}
}

CreateChildControls method
Our composite control consists of a label and a text box. We cannot use the technique of a simple control to display these two tags unless the coercion and Render () methods are used. Because we want to use adaptive rendering and display our two controls, we need to overwrite the CreateChildControls () method built into the CompositeControl class. This approach allows us to define the controls and pass the properties of our composite control to the individual controls to be displayed.

protected override void CreateChildControls () {
Create and load the label
Label LAB1 = new label ();
Lab1. Text = Prompt;
Lab1. ForeColor = this. ForeColor;
This. Controls.Add (LAB1);

Add a line break between the label and text box
Literal lit = new Literal ();
Lit. Text = "";
This. Controls.Add (lit);

Add the Textbox
TextBox TB = new TextBox ();
Tb.id = "TB1";
Tb. Text = Dateofbirth.tostring ();
This. Controls.Add (TB);

Call the parent method
Base. CreateChildControls ();
}

Note that we must initialize each control, assign all properties, and then add the control to the Controls collection built into the CompositeControl class. We also used the Literal object to line up the newline character
Placed between the label and the control. The Literal object is a very simple control that you can use to insert raw HTML between feature elements.

Note that we have also invoked the basic method to ensure that our composite controls have any other functionality built into the CompositeControl base class. In particular, the basic method forces asp.net to add all elements of the Controls collection to the control tree. If we ignore this call, or place it at the top of our method, the composite control will not be generated correctly.

The Complete Agecollector
When our Agecollector control is generated, asp.net actually calls the appropriate method on each child control and merges the results into the output of the composite control. In other words, if we have designed a simple control correctly, then the composite control is just a container. The adaptive rendering model is automatically applied to each child control. However, the actual compositecontrol will not be modified because it does not contain any controls that need to be changed.

Here is another instance where the appropriate method (CreateChildControls ()) takes advantage of the adaptive rendering model rather than simply overloading the Render () method on the WebControl. Because of the adaptive rendering model and CompositeControl features, ASP.net 2.0 saves our development time, reduces the number of lines of code, and reduces the number of test headaches. As soon as we know that the element control can be generated correctly through a specific adapter, CompositeControl will be generated correctly through that adapter.

If we drag the controls onto the ASP.net page and look at the properties, we'll see a single control with Prompt and dateOfBirth properties.



Figure 7. Agecollector use

Note that if we change the ForeColor of the composite control to red, we actually change the ForeColor of the Label. However, we have not yet linked some other properties. For example, we cannot change the ForeColor of the dateOfBirth field. In other words, when you build a composite control, you always need to consider which child control properties should be exposed.


Adding control behavior
So far, the two controls we've designed are simple, static controls. That is, these controls do not complete any operations that cannot be accomplished with a normal built-in control or simple user control (. ascx). One of the main reasons for building a custom server control is to provide new functionality that cannot be performed using an existing control set.

Event model
In a Web Forms page, the events associated with a server control are raised by the client and processed by the Web server. For events raised by server controls on the client computer, the ASP.net 2.0 event model collects information about the request and passes the details to the server using an HTTP Post. The Page Framework on the server interprets the bulletin to determine the event that occurred, and then invokes the appropriate handler method.



Figure 8. Typical server control events

ASP.net 2.0 handles almost all methods of capturing, transmitting, and interpreting events. Details are hidden for developers, and developers need only care about the implementation of handler methods on the server.

Most server events require a round trip to the server for processing and therefore support a limited number of click-type events. Mouse hover and other internal events are not supported for performance reasons.

Postback events
Many server controls in asp.net 2.0 generate postback events. The postback event passes the page to the server for processing. This is a very expensive operation because it requires the page to be delivered over the network.

The postback model has not changed significantly since ASP.net 1.x. In order to create a control that handles postbacks, your control must implement the IPostBackDataHandler interface, which defines two methods:

loadpostdata-This method handles postback data for your control.

raisepostdatachangedevent-This event notifies the application that the state of the control has changed due to processing postback data.


The event raised by the postdatachangedevent call must be defined inside the control. The user can then write the actual event method during the development process.

Non Postback events
Some server controls support non postback events. This type of event changes the state of the control, but does not require immediate processing. These events are cached by the control, rather than immediately passed to the server for processing. For example, a ListBox control might contain many elements. If the user chooses a different element, the control displays the appropriate changes and remembers their new state without notifying the server. After you post a form that contains a ListBox, the ListBox control submits the event (the selected item).

The default behavior for non-postback events can be changed by setting the AutoPostBack property. If AutoPostBack is set to True, the client-cached event sends a signal to notify the server to process immediately. A control that enables AutoPostBack requires that the client allow the script to run.

ASP.net 2.0 does not change the model in any obvious way.

Callbacks and Out-of-band requests
The standard WEB protocol is designed for synchronous communication. Each request receives a response at the same rate as the server generates the data. However, many tasks require out-of-band requests, such as access to third-party resources at the same time. These requests are not in the standard communication zone between the browser and the Web server, and are therefore considered out-of-band requests.

Out-of-band in the ASP.net 1.x
The requirements for Out-of-band data requests suggest that many developers can creatively use available resources to get the functionality they need. For example, by using ActiveX components and JavaScript, developers can make external HTTP calls without having to send a full postback to the server. The following JavaScript example illustrates an Out-of-band HTTP request that can be used with ASP.net 1.x.

function Retrievegooglefrontpage () {
var XmlHttp = new ActiveXObject ("msxml2.xmlhttp.4.0");
Xmlhttp.open ("Get", "http://www.fakedomain.com", false);
Xmlhttp.send ();
return xmlhttp.responsetext;
}

One drawback of this mechanism is that xmlhttp.responsetext contains the full result of the request. Developers will have to write special pages that return only business data, otherwise the response will be very large because of unnecessary markup.

asp.net 2.0 in the outer band
ASP.net 2.0 outlines the use of XmlHttp objects and provides built-in callback functionality. The core of the new system has two key items: System.Web.UI.ICallbackEventHandler and Page.getcallbackeventreference methods.

The Page.getcallbackeventreference method and its overloads are used to specify the JavaScript method that will participate in the callback event.

public string GetCallbackEventReference (
Control,
String argument,
String Clientcallback,
String context
);

The above code shows the minimum set of parameters required by GetCallbackEventReference, which are described in detail below.

The Control-control parameter determines the icallbackeventhandler of the implementation of the RaiseCallbackEvent method.

The argument-argument string contains client script. The results of the evaluation of the script are passed as eventargument parameters to the raisecallbackevent.

The clientcallback-clientcallback parameter contains the name of the client event handler that will receive the results of the successful server event.

The context-context parameter contains a client script. The results of the evaluation of the script are passed to the client event handler, which is specified as the context parameter in the Clientcallback parameter.


Callbackeventhandler and GetCallbackEventReference methods combine to generate asynchronous communication between the client and the server.


callback Example
The following Web page uses a callback mechanism to query the server for the current time. This page pops up a JavaScript warning to display the current time without a full page postback.

<%@ Page language= "C #" compilewith= "Default3.aspx.cs"
Classname= "Default3_aspx"%>
<%@ Register tagprefix= "CC1"
Namespace= "MyControls"
Assembly= "WebControlLibrary3"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd XHTML 1.1//en"
"Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >

<script language= "JavaScript" >
function GetServerTime () {
var message = ';
var context = ';
<%=CallBack%>
}
function Showservertime (timemessage, context) {
Alert (' The time on the server is:\n ' + timemessage);
}
function OnError (message, context) {
Alert (' A unhandled exception has occurred:\n ' + message);
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<cc1:timesnap id= "TimeSnap1" runat= "Server" > </cc1:timesnap>
<input type= "button" value= "GetTime"
Onclick= "GetServerTime ();"/>
</div>
</form>
</body>

The above page source code contains three key JavaScript functions: GetServerTime (), Showservertime (), and OnError (). These JavaScript functions are associated with getcallbackeventreference Out-of-band requests for the page.

Public partial class Default3_aspx {
public string CallBack;
void Page_Load (object sender, EventArgs e) {
CallBack = this. GetCallbackEventReference (TIMESNAP1,
"Message", "Showservertime", "context", "OnError");
}
}

The GetCallbackEventReference method requires an object that implements the ICallbackEventHandler interface for its first parameter. The TIMESNAP custom server control conforms to the interface requirements by implementing the RaiseCallbackEvent () method.

public class Timesnap:webcontrol, ICallbackEventHandler
{
...
public string RaiseCallbackEvent (string eventargument) {
Uncomment next line to test error handler
throw New ApplicationException (
"Some unhandled Exception");
Return DateTime.Now.ToLocalTime (). Toshorttimestring ();
}
}
}

The Timesnap.raisecallbackevent () method returns only the current time in string format.



Figure 9. Callback Request output

Figure 9 illustrates the result of pressing the GetTime button. An Out-of-band request is issued to the server, resulting in an "Alert" window showing the current time on the server. Sending this request does not require a postback, so the initial build time of the control does not change.


Using the designer
In the previous example, we have used several standard attributes to specify how the properties of a custom control will interact with the designer (Visual Studio). We assign attributes to the various control properties to define the categories in which the property will appear, define whether the property should have a default value, what the description of the attribute should look like, and whether the attribute should be bindable. In ASP.net 1.x, additional designer classes allow you to create new dialog boxes for editing properties, automatically convert property values from String to other data types (and vice versa), and display placeholder data for controls that are generated only at run time.

Designer classes help divide control development into two phases. First, you must develop custom controls. Second, you must decide how the developer will interact with the controls within the design environment. The designer class completes the second task by acting as an adorner at the top of each custom control. In other words, if you are developing many custom controls, you can create a standard reusable set of designers and simply apply the designer to each custom control with attributes.

ASP.net 2.0 provides several enhancements to the designer model:

• The new composite control designer-compositecontroldesiger Class fully recognizes the composite control and provides functionality to support parent-child control relationships.

• The new data-bound control designer-databoundcontroldesigner provides many new features for the databound control. You can use this designer to provide analog data, or to automatically connect to live datasource during design time.

• Enhanced standby design-time zone support-the new DesignerRegion class and its subclasses provide a very flexible mechanism for displaying controls. You can use DesignerRegion to set a tabbed view of the control. You can also use the EditableDesignerRegion control to create a new template for the control.

• Enhanced template Support-now the designer class provides a more concise mechanism for adding new templates to the control. A templated control is a control that separates the logic of controls from the display of controls. The display is defined through a template, and the logic is encoded in the actual control.

• Enhanced task Support-the designer can now incorporate design-time tasks. The most common tasks will be able to switch between views. However, other tasks can include automatic configuration of controls or automatic creation of resource files. A task can appear as a menu on a design-time control (similar to the menu that allows you to configure the GridView control).

• Enhanced event Support-the event model in the designer has been improved. You can now create events to respond to clicks in different areas or to the various tasks that you click. When you use the designer, you can enable the control to switch views, generate code, or change configuration as long as the user clicks on a specific area.


ASP.net 2.0 has a significantly improved designer model that makes it easier for professional control developers to work. If you're just building a single control for your own use, the designer is overqualified. However, if you are building a control for distribution, you can use a new designer to fully customize the behavior of the controls in Visual Studio 2005.


Summary
Although ASP.net 2.0 contains a rich set of extended controls, developers often have many reasons to create custom controls. Because of the enhancements in ASP.net 2.0, the process of creating custom controls is faster and easier than in ASP.net 1.x. The new CompositeControl base class takes full advantage of the adaptive rendering model and provides a simple, easy-to-use container for creating complex controls. If your control requires a postback or callback feature, ASP.net 2.0 simplifies the process of processing client-side script files and developing Out-of-band requests. Finally, after you develop the control, you can use various designer classes to fully configure the behavior of the control within the visual designer, such as Visual Studio 2005.



Related Article

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.