Asp.net control usage Problems

Source: Internet
Author: User

When I was using controls today, I encountered a small problem. Later I asked my predecessors to solve the problem. Now I want to share with you the hope that such a small error will not occur.
When the dropdownlist control is dragged, several basic drop-down options are set. To achieve this, click an item, the text displayed in the hyperlink and the corresponding link address change accordingly.

According toCodeYes:

 Protected     Void  Dropdownlist1_selectedindexchanged (  Object  Sender, eventargs E)
{
If (Dropdownlist1.text = " Qq " ) // If you select QQ
{
Hyperlink1.text = " Qq " ; // The text is QQ
Hyperlink1.navigateurl = " Http://www.qq.com " ; // The URL is QQ.com.
}
Else // Select Sohu
{
Hyperlink1.text = " Sohu " ; // The text is Sohu
Hyperlink1.navigateurl = " Http://www.sohu.com " // Urlsohu.com
}
}

The above Code uses the dropdownlist control. When you select different values
Row operation. When you select QQ, Configure connection as http://www.qq.com for the hyperlink1 control.
Note: like the label control, it is not recommended if you only want to implement hyperlinks.
Hyperlink controls, because excessive use of server controls can also cause performance problems.

However, the principle is correct, that is, the expected results cannot be achieved.
Previously, we forgot to set the relevant property: autopostback: true (the default value is false, that is, the value cannot be automatically returned and submitted to the background)
Setting this attribute can achieve the expected results. It's amazing ..

The following describes several properties of the effect:

1. autopostback attributes
In webpage interaction, if the user submits a form or executes the corresponding method, the page will be sent to the server. After the server executes the form operation or the corresponding method, and then present it to users, such as buttons and drop-down menu controls. If the autopostback attribute of a control is set to true, if the property of the control is modified, the page will be automatically sent back to the server.
2. The enableviewstate (control state) attribute viewstate is a mechanism used in ASP. NET to save the return status of Web controls. It is a hidden field managed by the ASP. NET page framework. When a callback occurs, the viewstate data is also sent back to the server. The ASP. NET Framework parses the viewstate string and fills in this attribute for each control on the page. After filling, the control uses viewstate to restore the data to the previous state.
When using some special controls, such as database controls, to display the database. It is unwise to execute a database round-trip every time you open the page. Developers can bind data and set only once when loading the page. In the subsequent return, the control will automatically refill the page from viewstate, reducing the number of database round trips, therefore, you do not need to use too many server resources. By default, the attribute value of enableviewstate is usually true.
3. Other attributes
The preceding two attributes are important, and other attributes are frequently used.
(1). maxlength: You can limit the length of the string you entered during registration.
(2). readonly: If this attribute is set to true, the value in the text box cannot be modified.
(3). textmode: This attribute can be used to set the mode of the text box, such as single row, multi-row, and password format. By default, if the textmode attribute is not set, the text box is a single row by default.

Thanks: Ya Fei

Related Article

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.