Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-02 10:05:24 09月28日 Update

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.

Tags: Control build control page property hierarchy identity uniqueness that is situation customer property is in schema result tradition content suffix client data Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB MySQL Huawei Xiaomi Apple