It’s the little things that keep you on your toes as a programmer. After my site upgrade to Community Server 2.0, Keyvan ever so politely pointed out that my CoComment script wasn’t working, i.e. coco enabled visitors weren’t having their comments automatically logged on the coco service. After a few minutes of digging around, I realized it was because in my original CS coco script I had hardcoded the commentFormName variable to always be __aspnetForm. Lo and behold my form name is different after the upgrade, so obviously hardcoding this value isn’t a good idea. Yeah, magic string syndrome.
The problem with this is that due to either A) The way CS2.0 skins name forms, or B) The way the asp.net runtime works when generating form names (don’t know which of the the two is the guilty party), the form name was no longer __aspnetForm and had become aspnetForm. Apparently this isn’t a constant, so back to the drawing board to get this value programatically. Unfortunately due to either A) The way CS2.0 skins name forms or B) How asp.net 2.0 generates form names (again, I have no idea who the guilty party is) this wasn’t as easy as simply changing the commentFormName variable declaration to Page.ID/UniqueID/ClientID (all came back as an empty string), and CS refused to compile when attempting to use Page.Parent.<whateverID>, coughing up a null reference exception.
What’s interesting is that Bob said there’s a Form member on the page class (which I didn’t see in the MSDN docs), which in turn has a Name property, so I gave that a shot and was promptly met with an accessor level denied error message (compiled under asp.net 1.1 but running on 2.0)…reflecting on System.Web.UI.Page revealed that there indeed was not a Form member on Page (as expected), so why that exception instead of a “member doesn’t exist” or whatever? Strange stuff, but after reflecting the same class on the asp.net 2.0 version of the assembly there is now a Page.Form member, and of course Form has a Name property which would have nipped all of this in the bud. So what’s the fix? Either recompile CS2.0 under asp.net 2.0 and use the afore mentioned solution, or simply change your comment form variable to the following javascript:
commentFormName = document.forms[0].name;
Yeah, it’s that easy (or difficult if you factor in how much time I spent digging through .Net documentation trying to figure out how to do this from server side code).
Share this post: 
|

|

|

|

|
