Powerful ASP. NET control----user control against custom controls

Source: Internet
Author: User

  1. user controls: using for specific programs
    1. example: User Control Login
      1. vs Span lang= "ZH-CN" style= "font-size:12pt" to create the program, as follows
      1. open UserControl.ascx

    1. Open UserControl.ascx under the UserControl.ascx.cs, write the following code:

Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.UI;using System.Web.UI.WebControls; Namespace usercontrol{publicpartial class UserControl:System.Web.UI.UserControl {protected void Page_Load (            Object sender, EventArgs e) {} publicstring txtusername//attribute 1: User name {Set            {This.txtName.Text = value;            } get {return this.txtName.Text; }} publicstring txtuserpwd//property 2: Password {set {This.txtPwd.Text = V            Alue;            } get {return this.txtPwd.Text; }}//control event protected void Btnlogin_click (object sender, EventArgs e) {if (Txtuserna            me = = "Liuying") && (txtuserpwd = = "Liuying")) {Response.Write ("login Successful");            } else{Response.Write ("Login Failed"); }        }    }}


    1. will be WebForm1 Set as the startup form, and then open WebForm1.aspx, switch to the design window, drag the user control into the page, Ctrl+f5 , start the program, enter a string in the text box, click Login, the interface will prompt the login success or failure.
  1. There are many ways to assign a property to a user control, and the above is a method of typing in a text box, and there is one way toWebForm1direct assignment in the user interface code form
      1. <uc1:usercontrol id= "Logincontrol" txtusername= "liuying" txtuserpwd= "liuying" runat= "Server"/>
      1. and in WebForm1 in the user interface design form, right-click the user control, select Properties

    1. Custom Controls: Custom controls are global, as long as they are set, all use this Visual Studio users can use the
      1. Example: namespaces are not very cumbersome to reference, and we often forget which class libraries should be referenced in a particular environment, such as D the namespace of the layer

    1. Whether the custom control or the user control, will give us the way of programming convenience, learn to use the two is not difficult, the best use is difficult!

Powerful ASP. NET control----user control against custom controls

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.