. NET user Control--un

Source: Internet
Author: User

User controls
What is a user control?
Custom reusable collection of controls

Benefits?
1. Code Reuse
2. Good structure
3. Division of Development
4. Local cache

Difficulties:
I. Exchange of information:
(i) Exchange information from the page to the user control. The code is written in the page.
1. User control name. FindControl ("ID of the control in the user control")
TextBox textBox1 = WUC1. FindControl ("TextBox1") as TextBox;

2. Define the public property in the user control beforehand by assigning a value or value to the control inside it.
Code in the user control:
public string TextValue
{
Get
{
return TextBox1.Text;
}
Set
{
TextBox1.Text = value;
}
}
The code in the page:
WUC1. TextValue = txt. Text;

(ii) Exchange information from the user control to the page. The code to write to the user control.
1.session
2. Agent

Two. Path:
1. Control path: Pictures, hyperlinks
Use the service-side controls. Standard controls or HTML tags plus runat=server.
This will automatically convert the server to the correct path.

2. Path to values in style sheet: background-image:url (path)
Instead of using inline styles, use an external style sheet to control the picture path.

3. External resource path-the introduction of external script files in user controls
Use string path = Resoveclienturl ("Server-side path"); Returns the corresponding path for the client
HTML code:
<script src= "<%= showscriptpath ()%>" ></script>
C # code:
public string Showscriptpath ()
{
String path = "Scripts/javascript.js";
Path = this. Resolveclienturl (path);
return path;
}

The call path of the 4.c# code
Response.Redirect ("page");
Use the root of the application path to resolve
Response.Redirect ("~/default.aspx")

. NET user Control--un

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.