471,595 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,595 software developers and data experts.

Need help getting the value in a HiddenField!

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
Oct 18 '06 #1
3 6775
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.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
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

Oct 18 '06 #2
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)

"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
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

Oct 18 '06 #3
thanks
"Mark Fitzpatrick" <ma******@fitzme.comwrote in message
news:uE*************@TK2MSFTNGP04.phx.gbl...
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.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
>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


Oct 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by sklett | last post: by
reply views Thread by =?Utf-8?B?cGI2NDgxNzQ=?= | last post: by
4 posts views Thread by bushi | last post: by
3 posts views Thread by KBTibbs | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.