>I was doing some testing today to find out why one of our ASP.NET web apps wasn’t working in Firefox. It boiled down to the fact that ASP.NET’s Page.RegisterHiddenField() method doesn’t set the ‘id’ attribute of the element it creates, only the ‘name’ attribute. This in turn breaks Firefox’s getElementById because in Firefox (and all other Mozilla-based browsers, as I understand) the id and name namespaces are not merged (as they are in IE). So getElementById() in Firefox will never find a hidden element created by using RegisterHiddenField().
The simple workaround is to use a HTML Hidden Input element as follows in the ASPX page:
<input type=”hidden” id=”myHiddenElement“ runat=”server” value=”myvalue” />
Then in the .cs codebehind you can declare your hidden element as follows:
protected System.Web.UI.HtmlControls.HtmlInputHidden myHiddenElement;
and you can manipulate the control in the codebehind as follows:
this.myHiddenElement.Value = “some value”;
I would consider this a bug in the RegisterHiddenField() but if someone can explain why it isn’t, I’d LOVE to hear why.