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?
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.