views:

160

answers:

1

Hey All,

I have some code which is rendering some custom attributes of Hidden Control (without runat=server).

Something like,

And I have a lot of these hidden elements on my form.

When I submit the form, I am looping through a set of ids, say 1200 to 1250, so I will read controls based on that, and also hidden with Request.Form["hdn "]

Now problem is, as we know we get value attribute from form when we do Request.Form["id"] for hidden, I want to read my custom attributes from hidden element. Is there any way? Note that, I can not touch the rendering part here.

Thanks.

Jimmy.

+1  A: 

I don't think this is going to work - if you're dealing with plain HTML controls (i.e. ones without the runat="server" attribute), then when they're posted in a form, all you get is a load of key-value pairs, corresponding to elements' IDs and their Values.

When you do Request.Form["id"], you're not getting the element, you're just getting the value of that element (i.e. whatever was in the element's value attribute). There's no way to get access to the contents of any other attributes, custom or otherwise.

You'll either need to add the runat="server" attribute to these controls and then pick them up in a postback, or use some crazy javascript to pick out the custom attribute values and stick them in the form id/value collection somehow.

Graham Clark
Graham,Thanks for the answer.As I said it is not possible for me to change rendering code. Actually I too thought the same, that with this rendering only way is to have some javascript which concates all my custom attributes to value of that hidden element.I would still love to have some way (better way) out of this.Thanks,Jimmy.
Jimmy