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