There is a lot of code that can be repeated when writing code.
Like the top and bottom of a website
Almost every page needs it.
User controls can help solve this problem.
I. Examples of usage
1. Use the top of the page to add pictures and themes to decorate the site
2. Here is a row of jump buttons. Like the effect of a menu
3. You can also add a profile picture to ensure that each page can see the avatar
Running an instance
This is a complete user control. When other pages are called, it's all right.
Two. Writing user controls
1. Add a Form User control
2. Fill in the code for the user control
It is not allowed to add tags such as html,body,form
<%@ Control language="C #"autoeventwireup="true"Codebehind="Top.ascx.cs"inherits="Library.Common.Top"%><BR/><asp:image id="Image2"runat="Server"/><asp:button id="Btndata"runat="Server"text="My Profile"onclick="Btndata_click"/><asp:button id="Btnhis"runat="Server"text="Borrowing History"onclick="Btnhis_click"/><asp:button id="Btnbook"runat="Server"text="Book Search"onclick="Btnbook_click"/><asp:button id="Btnword"runat="Server"text="Message History"onclick="Btnword_click"/><asp:button id="Delete"runat="Server"text="Logout"onclick="Delete_click"/><BR/> <asp:imagebutton id="Image1"runat="Server"height="100px"Width="100px"onclick="Image1_click"/><div style="margin-left:200px"> <asp:panel id="Panel1"runat="Server"visible="false"> <asp:fileupload id="FileUpload1"runat="Server"/> <asp:button id="Btnupload"runat="Server"text="Upload"onclick="Btnupload_click"/> </asp:Panel></div>
3. Customizing properties for user controls
string name; int ID; Public string text { get { return name; } Set { this. Name = value; } }
4. Reference user Control Examples (can be understood against ASP tags
<%@ Register tagprefix= "uc1" tagname= "Top" src= "~/common/top.ascx"%>
)
<%@ Page language="C #"autoeventwireup="true"Codebehind="Liberary.aspx.cs"inherits="Library.Common.Liberary"%><%@ Register tagprefix="uc1"Tagname="Top"Src="~/common/top.ascx"%><! DOCTYPE html>"http://www.w3.org/1999/xhtml">"Server"> <title></title>"Form1"runat="Server"> <div>Welcome<asp:label id="Label1"runat="Server"text="Label"></asp:Label> Join the Grand Marine Library <br/> <uc1:top id="TopText"runat="Server"/> <br/> Your location >>Sea-Big library</div> </form></body>At this point, it's over. Why don't you just wash up and sleep now?
Some uses of the user control