Different .Net Versions Name Data Grid Elements Differently

Posted on 2011-05-09
Last Modified: 2012-05-11
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.



Question by:jjwild0
    LVL 44

    Expert Comment

    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.
    LVL 17

    Expert Comment

    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.

    Author Comment

    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?
    LVL 17

    Accepted Solution

    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).

    LVL 17

    Expert Comment

    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 Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
    Configuring network clients can be a chore, especially if there are a large number of them or a lot of itinerant users.  DHCP dynamically manages this process, much to the relief of users and administrators alike!
    The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now