In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail what are the useful properties of the ASP.NET control. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1 、 ClientIDMode
An ID is automatically generated when rendering ASP.NET controls, but it creates a lot of trouble when we reference them in client script. Although it is a simple concatenation of naming containers and ID, it is still impossible to predict the scope of the generated ID.
ASP.NET 4. 0 solves this problem with the ClientIDMode attribute, which allows you to control how these ID are generated. ClientIDMode has four optional values: AutoID,Static,Predictable and Inherit. Here is an explanation of the meaning of these four values:
AutoID-consistent with versions prior to 4.0, ID is automatically generated.
Static-you specify the value of ID and will not change when rendering the control.
Predictable-you specify the suffix and merge it with the ID property of the container control.
Inherit-inherits the settings of the parent control.
Note that the default ClientIDMode property of Page is AutoID, which can be set at the page level through the @ Page directive, and you can also set the value at the application level by modifying the Web configuration file.
[pre] [/ pre]
2. Meta keyword and Meta description
Page class in ASP.NET 4.0 added two new attributes: Meta Keywords and Meta Description, you can set these two properties at run time, through the database or other source drivers, and allows you to dynamically set tags to describe a specific page, the following Page tag shows these two attributes.
[pre] "C#" AutoEventWireup= "true" Keywords= "keyword1, keyword2" Description= "my description"% > "C#" AutoEventWireup= "true" Keywords= "keyword1, keyword2" Description= "my description"% > [/ pre]
3. Row persistence selection in data-bound controls
ASP.NET data-bound controls, such as Grid View, support row selection, but they should select rows with the same number on each page, but in versions prior to ASP.NET 4.0, row persistence selection was not possible because previous versions selected rows on subsequent pages based on row indexes, and ASP.NET 4.0 provides an intuitive way to solve this problem.
The data-bound control now provides an EnablePersistedSection property that helps me implement the row persistence selection. The following code shows the List View control that uses the EnablePersistedSelection property.
[pre] "server" EnablePersistedSelection= "True" DataSourceID= "dsRanks" DataKeyNames= "rankid" > "server" EnablePersistedSelection= "True" DataSourceID= "dsRanks" DataKeyNames= "rankid" > … ... [/ pre]
4 、 AutoEventWireup
AutoEventWireup is a rarely used but well-known ASP.NET attribute. To put it simply, when it is set to True, it allows you to automatically call page events without explicit delegation. The following code snippet shows the use of the AutoEventWireup attribute.
Its default value is the True,AutoEventWireup attribute. The disadvantage is described in detail on MSDN: "it limits the flexibility of naming event handlers, another disadvantage is the adverse impact on performance, for high-traffic sites, the performance impact is huge."
5. Header attribute of Page
The Page class now provides the Header property, which can be bound at run time, and the following code example shows how to explicitly set the Title property.
This.Header.Title = "My page title"
This property is convenient when you dynamically associate a stylesheet according to a rule, in which case a printed page is an ideal candidate.
[pre] HtmlLink printLink = new HtmlLink (); printLink.Attributes.Add ("type", "text/css"); printLink.Attributes.Add ("rel", "stylesheet"); printLink.Attributes.Add ("href", "css/print.css"); this .Header.Controls.Add (printLink); [/ pre]
6. AssociatedControlID attribute
You can associate a control to another server control in a Web form, using the server control's AssociatedControlID property, which comes in handy when you want to set hotkeys for the associated control based on certain behaviors.
[pre] "txtUserName" runat= "server" Text= "User name:" / > "txtUserName" runat= "server" Text= "User name:" / > [/ pre]
The default value of the AssociatedControlID property is an empty string that indicates that the control is not associated with any server control, and the following code shows how a Textbox control is associated with a Label server control.
7. ControlState attribute
ASP.NET 's most important state management technology is ViewState, which allows you to retain values on the way to and from the Web server, but because it can be turned off at the parent, it is not a reliable way to save information.
ASP.NET 2.0 introduces a proprietary ViewState for server controls called ControlState, which can be used to store key information about the control, and ASP.NET can handle its serialization and deserialization.
Note that you must be careful when using it, as it can affect the performance of the page.
8 、 Control.PreserveProperty
For the traditional use of view state, Rick Strahl provides us with another option: PreservedProperties, which can save the control ID and property names. For more information, please refer to "Implementing an ASP.NET PreserveProperty Control (implementing ASP.NET PreserveProperty controls)".
9. Browser-based properties?
ASP.NET 2.0 provides us with a way to specify a browser filter for properties, and just when I was confused, I happened to visit Ryan Farley's blog, and he said he was just as confused when he saw John Katsiotis's blog.
In fact, you can set different values for properties according to different browsers, as shown in the following example (the code is from Ryan Farley's blog).
[pre] ie:OnClientClick= "_ javascript:alert (" Hello IE! ");" mozilla:Text= "FF Button" mozilla:OnClientClick= "_ javascript:alert (" Hello Firefox! ");" Text= "General Button" OnClientClick= "_ javascript:alert (" Hello everyone else! ");" / > [/ pre]
Interesting, isn't it?
10. PreviousPageType instruction
The PreviousPageType directive is part of the ASP.NET 2.0 cross-page echo mechanism, which allows you to specify a virtual path to the source page for strongly typed access to the source page. Normally, the data sent can be accessed through the PreviousPage property and the FindControl method, but using strongly typed PreviousPageType instructions allows you to access public properties without calling the FindControl method.
For example, suppose you have a page called firstpage.aspx, which has a public property FirstProperty, and now in your second page (secondpage.aspx), you can add the following code:
[pre] "firstpage.aspx"% > "firstpage.aspx"% > [/ pre] then call the property of * pages [pre] var firstPageProperty = PreviousPage.FirstProperty; [/ pre]
There are many kinds of ASP.NET controls, and the properties of each control are not exactly the same.
Through the analysis of this article, I believe you have a deeper understanding of these 10 attributes. The above is all the content of the article "what are the useful properties in the ASP.NET control?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
This is the end of this article on "what are the useful properties in the ASP.NET control?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.