Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the improvements to the new features of ASP.NET 4.0?

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you some improvements about the new features of ASP.NET 4.0. the article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.

In the new features of ASP.NET 4.0, improvements to ClientID can control the ID of the generated Html when executing nested spaces. In the past, when doing such an operation, it was easy to make mistakes and difficult to control.

One: brief introduction

We know that because it is difficult to control the use of server-side controls in the original ASP.NET application when generating ClientID, especially when nested controls, such as multiple nested Repeater, are difficult to control the ID property of a html generated by a control.

ClientMode is provided in the new feature of ASP.NET 4.0 to control the ID of the generated Html.

Second: the original problems and solutions

It turns out that to get the ID of html, you need to use this method:

Var lblName = document.getElementById (""); alert (lblName.innerText)

If you are in a nested control, you need to use a parallel string to combine the client ID

For (var I = 1; I td > td >

So it can be seen that it is more suitable for the use of a single control.

If the repeater is set to Static and the later control is set to Predictable

Asp:SqlDataSource > sfsdtd > tr > HeaderTemplate > asp:Label > td > tr > ItemTemplate > FooterTemplate > asp:Repeater >

The result is:

It seems to be quite flexible.

Now we have another one on the outside of repeater: Label,ID is lblName_0, ClientIDMode is Static or Predictable

Asp:Label > asp:SqlDataSource > sfsdtd > tr > HeaderTemplate > asp:Label > td > tr > asp:Label > td > tr > asp:Label > td > tr > ItemTemplate > FooterTemplate > asp:Repeater >

The result will appear on the page.

But it didn't get it wrong.

If you add another one with Label,ID as lblName_0 and ClientIDMode as Static or Predictable, an error will occur.

Asp:Label > asp:Label > asp:SqlDataSource > sfsdtd > tr > HeaderTemplate > asp:Label > td > tr > asp:Label > td > tr > asp:Label > Td > tr > ItemTemplate > FooterTemplate > asp:Repeater >

At this time, an error will be reported, with the same ClientID.

Therefore, the use of ClientIDMode has a hierarchical scope, and you can't have the same ID at the same level on the page. If you have the same ID in the new level in Repeater, you can have the same ID in the previous level.

(3) Predictable Mode

There is also a new property ClientIDRowSuffix in the GridView data-bound control, which is set in GridView to use the Predictable mode to generate the suffix of the new ID.

Asp:Label > ItemTemplate > asp:TemplateField > Columns > asp:GridView >

The resulting result is:

ProductNameth > tr > Chaispan > td > tr > Changspan > td > tr > Aniseed Syrupspan > Td > tr > Chef Anton's Cajun Seasoningspan > td > tr >

You can see that we use ProductName as the suffix.

Summary of new features

Now with this ClientMode, you can well control the ID generated to the client, so you can better control the tags on the page dynamically.

If you want to know more about it, you are welcome to follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report