Need help getting the value in a HiddenField!

J

Jeff

Hey

ASP.NET 2.0

Below you see the code I'm having problem with. In the Open_Message
event/method I want to get the value of the HiddenField at the row in the
repeater control I clicked.... my goal is to get the id (not a control Id,
but an id related to a database record) of a row in the repeater control. I
don't want to use Get... I've tryed to use e.FindControl in the Open_message
event but FindControl isn't available, so I don't know how to get the
value....

<asp:Repeater ID="rptMessages" runat="server" DataSourceID="odsMessage"
OnItemDataBound="Display_Messages">
<HeaderTemplate><table width="100%"></HeaderTemplate>
<ItemTemplate>
<asp:HiddenField ID="fhId" runat="server" />
<tr>
<td >
<div style="width:100%; height:100%; background-color:Lime;">
<div style="width:75px; height:75px; float:right;">
<asp:ImageButton ID="MemberPhoto" runat="server" Width="75px"
Height="75px" />
</div>
<asp:Label ID="lblHeader" runat="server" Text=""></asp:Label>
<asp:LinkButton ID="lbkLinkToMessage" runat="server"
OnCommand="Open_Message">Reply</asp:LinkButton>
<asp:Literal ID="ltMessage" runat="server"></asp:Literal>
</div>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>

protected void Open_Message(object sender, EventArgs e)
{
HiddenField hiddenField = (HiddenField) e..Item.FindControl("fhId");
********* here is my problem
//FindControl isn't available here, this code don't compile.........
}

Any suggestions?`

Jeff
 
M

Mark Fitzpatrick

You can't use findcontrol to do this. The findcontrol will attempt to look
for subcontrols of a linkbutton, which doesn't have any subcontrols. You
have to make the field available to the linkbutton itself. You could do this
by setting the commadnname or commandargument properties of the linkbutton
ot the hidden fields' id instead of attempting to get the hidden id, which
is impossible.
 
B

bruce barker \(sqlwork.com\)

you will notice that the button and the hidden are children of the template
item. this means you just walk up the control hiearchy to the template, then
find the control.

Control ctl = Parent;
while (!(ctl is ITemplate)) ctl = ctl.Parent ;
HiddenField hiddenField = ctl.FindControl("fhId");

note: if the hidden was contained in another control, once you found the
template, you would have to do a recursive find for the control.

-- bruce (sqlwork.com)
 
J

Jeff

thanks


Mark Fitzpatrick said:
You can't use findcontrol to do this. The findcontrol will attempt to look
for subcontrols of a linkbutton, which doesn't have any subcontrols. You
have to make the field available to the linkbutton itself. You could do
this by setting the commadnname or commandargument properties of the
linkbutton ot the hidden fields' id instead of attempting to get the
hidden id, which is impossible.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top