Server controls-simple server controls-Notes (1)

Source: Internet
Author: User

Using system;
Using system. Web. UI;

Namespace simplecontrol
{
Public class simplecontrol: Control
{
Protected override void render (htmltextwriter writer)
{
Writer. Write ("I don't do anything useful ,");
Writer. Write ("but at least I'm a control ...");
}
}
}

System. Web. UI. htmltextwriter is a tool class,

It encapsulates the function of writing HTML into text streams.

Simplecontrol simply transfers text to the write method of the htmltextwriter instance.

It is equivalent to the functions implemented by response. Write, which transfers the specified text to the HTTP Response stream.

Do not directly call page. response. Write from the control, because this will break the page framework encapsulation.

 

Create a Project B.

Deploy the user control just created

___

Compile and deploy server controls:

Change the previous project generation path to the bin directory of Project B and regenerate

___

Use custom server controls:

Go to Project B

On the default. aspx page of the reference control, add:

<% @ Register tagprefix = "MSP" namespace = "mspress. servercontrols" assembly = "mspress. servercontrols" %>

Tagprefix: creates an alias.

Namespace: Specifies the namespace declared by the custom control.

Assembly: Specifies the accessory that the control will generate.

Add

<Body>
<Form ID = "form1" runat = "server">
<Div>
<MSP: simplecontrol id = "simple1" runat = "server"/>
</Div>
</Form>
</Body>

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.