Reputation: 97
Inside repeater's itemtemplate I have a Panel server control.
I need to assign special Id for it, because I need to work with some javascript functions that use this Id.
In repeater ItemDataBound event I have this:
pnlButtonsPanel.ID = pnlButtonsPanel.ID + DataBinder.Eval(e.Item.DataItem, "ID");
But this solution is not good because after a postback the page is re -rendered and I lose the new ID. (And I don't want to rebind repeater after every postback)
I tried to set the ID on aspx page like that:
<asp:Panel id='<%# Eval("ID") %>'
and some other variations but always get compile errors.
Upvotes: 0
Views: 1944
Reputation: 21905
in asp.net 4.0 you will be able to do this.
Which isn't too helpful right now...
One way to do this would be to assign your id as the cssclass property of the control, then use jQuery client side to find it:
<asp:Panel id='panel_thingy' cssclass='<%# Eval("ID") %>'
$(".123") // selector for panel with class (id) 123
Edit: since you are not using jQuery, here are two more possibilities. First, instead of a Panel control, you could use a plain <div>
(do not use runat="server" in the tag). Then you can set the id exactly the way you want to do it.
Or, if that doesn't work for you, you can grab the ClientID of the Panel in your ItemDataBound event handler and store it in a collection of some sort (for example, a Dictionary where the key is the item id, and the value is the panel ClientID). Then after the repeater is populated, you have a list that you can write out to the client as a javascript array (or some JSON thing, or whatever works for your client-side coding needs).
Upvotes: 2