ASP.net's user control experience

Source: Internet
Author: User
Asp. NET's user control
Brief introduction
Asp. NET's server-side controls make Web development work easier and more powerful. We have described how to use server-side controls in asp.net pages. But what if the server does not have the required controls?
Of course, ASP. NET will not give you a false control. In fact, you can replace it with your own control. NET provides a control. This kind of control is the user control, also is the topic which this article discusses.
Writing the first user control
Some people think that knowing how to use a server-side control does not necessarily mean that it is easy to write a user control.
In fact, writing a basic user control (sometimes called a pagelets) and making asp.net pages use them like server-side controls is a simple thing to do. Here's a simple example:
Basic.ascx
<p>
This is a user control ... really!
</p>
This is a user control! See here, I think you will say I am not drunk, the mind is not clear. But this code is indeed a user control that is easy to use. Although this control does nothing, it is a good illustration of what a user control is. Things are not as complicated as you think. Note the suffix. ascx, which tells the Web page that this is a user control. It doesn't have any special meaning, it just doesn't allow IIS to execute the code directly.
Now let's create a user control that looks at the following example:
Basic.aspx
<%@ Page language= "VB"%>
<%@ Register tagprefix= "Asp101samps" tagname= "Sometext"
Src= "Basic.ascx"%>
<title>asp.net User Control sample-basic</title>
<body bgcolor= "#FFFFFF" >
<asp101samps:sometext runat= "Server"/>
</body>
This code outputs the standard HTML page, displaying the text in the user control instead of the tag.
So how does it happen? The key is in the registration (register) description. To register a control, you first define three properties:

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.