ASP. NET ~ Logon demo for user control optimization, asp. netdemo

Source: Internet
Author: User

ASP. NET ~ Logon demo for user control optimization, asp. netdemo

To learn about user controls, we can only understand the following aspects:

1) What is a user control?

Server Control created in declarative form! Compared with the general control, its biggest advantage is that it can be used repeatedly on multiple pages of the same Web application, reducing its repeated operability and adding its own attributes, events and Methods


2) What are the features of user controls? What are the similarities with Web forms?

  • Similarities:

One user interface page

A code hidden file

  • Similarities and Differences:

User Control: the extension is. ASCX.

The user control does not contain <HTML> <BODY> <FORM>

Therefore, the two can be converted to each other.

The method for adding a user control is actually like adding a web form. It works like a template.

3) demo:

I did not use this method when I used to log on to the data center and niuxi. At that time, I was confused. Now I have a clear understanding.

The control added in the user control can be directly aligned and assigned values, for example, for txtUserName (note that the txtUserName has been defined when writing code, so it must be in lower case when you use it again, or use another name)

public string  txtusername        {            set            {               this.txtUserName.Text =value ;                            }            get            {                return this.txtUserName .Text ;            }        }
This is the correct use of set and get. set Value assignment and get value passing

Web form call:

A user control is called in a web form and has an encapsulation concept. Therefore, a user control can be called only through its attributes.


Pass value:

// If you cannot find it, use findcontrol to find it. The conversion type is response.write((testcontrol+this.tc1+.txt username); // response.write((testcontrol+this.tc1+pwd );
Assignment:

            ((testControl)this.tc1).txtusername="huohuo";            //((testControl)this.tc1).txtpwd = "111";
Display Effect:



Especially for those that we need to call an error but do not want to hide the form, we can fill in the relevant information in the HTML code related to the user form: (save a lot of trouble)


4) Conclusion:

1. controls one by one are actually interrelated. Just like this user control, we can actually know from the name that it serves the user wholeheartedly and better meet the user's needs.

2. Step-by-Step accumulation is essential to differentiate the similarities and differences and summarize them.

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.