ASP.NET / ASPX: "Unexpected duplicate node name for HTML cache"
Hi Phil
Looked through your log-file to find out why scanning is giving me a hard time in aspx files. I'm not sure I found my issue, but I found another one + a solution.
Please look at this code snippet:
https://gist.github.com/anonymous/cda2ce18befd57a74f8a9ccea522e043
The Error I'm getting is something like:
11:21:48.280858: Unexpected duplicate node name for HTML cache Test.aspx.Literal1.Text
And basically the error occurs because of the usage of "GridView" (could have been ListView or other similar controls). Basically I would recommend you reconsider your "cache naming".
As is, it would try to insert 3 items into the cache:
- Test.aspx.Literal1.Text
- Test.aspx.Literal1.Text
- Test.aspx.Literal1.Text
3 items with the same name, giving duplicate name error.
ASPX Control ClientID
This is actually a situation handled by ASPX already. Every control has a "ClientID" (as well as ID). "ClientID" will kind of contain the ParentID's, but not in all parent IDs. It depends if the control is having it's own scope or not - not sure how this is determined, when I look at PlaceHolder, this does not have it's own scope, but GridView does.
In my example it could be 3 ID's like
- ctl00_ctl00_Literal1
- ctl00_ctl00_GridView1_ctl02_Literal1
- ctl00_ctl00_GridView1_ctl03_Literal1
Suggestion
If you are not able to use "ClientID" (or prefer not to), you could consider some way to find out if a ParentID defines a new scope or not, so e.g. GridView name becomes part of your name like:
- Test.aspx.Literal1.Text
- Test.aspx.GridView1.Literal1.Text
- Test.aspx.GridView2.Literal1.Text
Not sure how to do this. There might be an Attribute (PersistenceModeAttribute (PersistenceMode enum) on GridViewColumns?) in relation to the GridView that could tell this, maybe it's the ITemplate type or similar..
This could explain some issue I've had in the past (since auto-generated ID's can cause some nasty issues).