Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

Different .Net Versions Name Data Grid Elements Differently

I have a VB.Net app written in .Net 1.1.  I need to update it so our clients can run it with more recent versions of .Net.

Most of it works fine with no changes.

The problem is with datagrids.  We have alot of Javascript triggered by client side events that goes through datagrids and does various things.  These scripts need to know the ID's of the elements in the different data rows, ie. as assigned by IIS when the HTML is sent to the client browser.

If run using 1.1, the txtText textbox on the first row of datagrid dgGrid is dgGrid__ctl2_txtText .

In run using 2.0, the txtText textbox on the first row of datagrid dgGrid is dgGrid_ctl02_txtText.

In run using 4.0, the txtText textbox on the first row of datagrid dgGrid is just txtText.  However, it does assign the control's name a unique value which I can use,  dgGrid$ctl02$txtText.

These are the changes I have found.  I am trying to find a reference on this somewhere so I can know that once I do make changes to the Javascript, I can rely on the result.

> Does anyone have any data on something that documents exactly what changes were made to the ID and name handling?

> And hopefully why they were made?  An understanding is always useful.

> Also, does anyone have a good solution on how to handle this? Finding out the name of the control on the server and passing it to the browser is not preferable due to the possibly large number of controls involved.



  • 3
1 Solution
I'd suggest you abstract the names for the Javascript code, if possible, based on the .Net framework version.  This all depends on the ability of the Javascript code to reference controls by parameterized name.  The original name or grid address might be sent to a routine that conditionally adjusts the name or calculates the name from the address and returns the correct name for the framework version.

I won't be able to help you with any details, as this isn't my strongest EE zone.  However, that is the approach I'd try to take if faced with a similar problem.
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
You should insert the ID's from the serverside into the clientside using the controls ClientID property. Note that with .NET 4.0, you can get total control over the naming scheme used for controls, meaning you cannot trust the default generated names will always be the same.
jjwild0Author Commented:
I have 400 K of debugged stable custom Javascript.

I am trying to find a solution that does not require doing so many changes that it triggers a full QA.

What I am trying to do first is gain an understanding of the exact changes and why.

> I could handle the changes by using ClientIDMode except that it works in 4.0 only.

> I realized that I can create code on the backend to find the ID assigned to a control on
    the front end.  That gets into many changes.

Does anyone know any issues from Microsoft that detail the changes to the id and name handling in the different versions of .Net?
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
Changes between 2.0 (3.0 and 3.5) and 4.0 are documented pretty well, due to the architectural change in the way clientids are generated. You could set this to Legacy, that should give you the same ClientId as you had in .NET 2.0.

Changes between 1.1 and 2.0 are not well documented. Partly because you weren't supposed to rely too much on the way the ID was generated, but you were supposed to inline the ID as documented in the article above. The few references I do know of have to do with changes made to ensure XHTML compliance. You can turn that off by setting the xhtmlconformace mode to Legacy. Though I'm not sure it will fix your problem (or cause new problems because of rendering changes).

Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
As a side note, I'm not sure if setting the 4.0 mode to legacy can be combined with the 2.0 xhtmlconformance=legacy so that you'd have the same clientid's on all framework versions.

Whichever way you choose, make a note to change that javascript library the next time you need a full QA anyways.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now