Apr 4 2007

RegisterHiddenField and ID property

Category: ASP.NET 2.0 - GeneralBil@l @ 10:43

In a previous post I talked about the xListBox and MoverList Controls. I did some fixes to make them work for FireFox and IE.

What was the problem actually? If you read the article about xListBox, you will notice that I have based on solution on a HiddenField to keep track of added/removed items from the ListBox on the client side and to reflect the changes on the server side.

The problem was that, RegisterHiddenField in ASP.NET 1.1, was not generating an ID for the hidden field on the HTML and I was using the document.getElementById, FireFox was having a problem in this, while IE as usual has no problem with anything [:D].

I could have used document.getElementByName, but I prefered to use the one by ID. So what I did is that, I had to customize the way the RegisterHiddenField works. The idea I got from this post: ASP.NET's RegisterHiddenField and document.getElementById

However, I had to modify it a bit to look something as:

    string hiddenFieldName = this.ClientID + "_REMOVED";
    if (!HttpContext.Current.Request.Browser.ToString().Equals("IE"))
        hiddenFieldName =  hiddenFieldName + "\"" + " id=\"" + hiddenFieldName;

This way, I did a trick to add the name of the HiddenField and an ID for the HiddenField and that worked perfect!!

Maybe you can use this trick in your work somewhere!

Hope this helps,
Regards

Tags:

Comments are closed