ASP. NET Web User control

Source: Internet
Author: User
Tags tagname

While we were writing our web site, we could customize some of the controls to reuse them, in addition to using their fixed server controls.

Add a Web user control that lets you add content in front-end and behind the scenes, add a Web form, and drag Web user controls into the web The form corresponds to the place.

Note that the user control cannot be set as the Start page, and when dragged into a Web form, the Web form is changed to design mode before it can be dragged into success.

The following code is dragged in:

Front:

<%@ Register src= "Ww.ascx" Tagname= "ww" tagprefix= "uc1"%>// Generation Dock

Ww.ascx for user controls

<UC1:WW id= "WW1" runat= "server"/>// drag in the corresponding place

Accessing the properties of a user control

For example, aWeb form wants to get the value of a property of a user control.

User controls:

Background:

public string name = "Chen";

public string name{

get {return name;}

set {Name=value;}

}

Web Forms:

Front:

<%@ Register src= "Ww.ascx" Tagname= "ww" tagprefix= "uc1"%>// header

<UC1:WW id= "WW1" runat= "Server"/>

<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>

Background:

TextBox1.Text = This.ww1.name.ToString ();//Gets the name value of the user control, which is displayed on the TextBox control

To access a server control for a user control

such as a small example of login

User controls:

Front:

<asp:textbox id= "TextBox1" runat= "Server" ></asp:TextBox>

Background:

public string name{

get {return textbox1.text;}

set {TextBox1.Text = value;}

}

Web Forms:

Front:

<%@ Register src= "Ww.ascx" Tagname= "ww" tagprefix= "uc1"%>// header

<UC1:WW id= "WW1" runat= "Server"/>

<asp:button id= "Button1" runat= "Server" text= "button" onclick= "Button1_Click"/>

Background:

protected void Button1_Click (object sender, EventArgs e)

{

if (this.ww1.Name.ToString () = = "123")

{Response.Write ("<script>alert (' login successful ') </script>");}

else {Response.Write ("<script>alert (' Login failed ') </script>");}

}

ASP. NET Web User control

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.