Some uses of the user control

Source: Internet
Author: User

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"%&GT;&LT;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"/&GT;&LT;BR/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<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

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.