473,574 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="o dsMessage"
OnItemDataBound ="Display_Messa ges">
<HeaderTemplate ><table width="100%"></HeaderTemplate>
<ItemTemplate >
<asp:HiddenFiel d ID="fhId" runat="server" />
<tr>
<td >
<div style="width:10 0%; height:100%; background-color:Lime;">
<div style="width:75 px; height:75px; float:right;">
<asp:ImageButto n ID="MemberPhoto " runat="server" Width="75px"
Height="75px" />
</div>
<asp:Label ID="lblHeader" runat="server" Text=""></asp:Label>
<asp:LinkButt on ID="lbkLinkToMe ssage" 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(ob ject sender, EventArgs e)
{
HiddenField hiddenField = (HiddenField) e..Item.FindCon trol("fhId");
********* here is my problem
//FindControl isn't available here, this code don't compile........ .
}

Any suggestions?`

Jeff
Oct 18 '06 #1
3 6847
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.NO SPAMwrote in message
news:OF******** ******@TK2MSFTN GP02.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="o dsMessage"
OnItemDataBound ="Display_Messa ges">
<HeaderTemplate ><table width="100%"></HeaderTemplate>
<ItemTemplate >
<asp:HiddenFiel d ID="fhId" runat="server" />
<tr>
<td >
<div style="width:10 0%; height:100%; background-color:Lime;">
<div style="width:75 px; height:75px; float:right;">
<asp:ImageButto n ID="MemberPhoto " runat="server" Width="75px"
Height="75px" />
</div>
<asp:Label ID="lblHeader" runat="server" Text=""></asp:Label>
<asp:LinkButt on ID="lbkLinkToMe ssage" 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(ob ject sender, EventArgs e)
{
HiddenField hiddenField = (HiddenField) e..Item.FindCon trol("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.NO SPAMwrote in message
news:OF******** ******@TK2MSFTN GP02.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="o dsMessage"
OnItemDataBound ="Display_Messa ges">
<HeaderTemplate ><table width="100%"></HeaderTemplate>
<ItemTemplate >
<asp:HiddenFiel d ID="fhId" runat="server" />
<tr>
<td >
<div style="width:10 0%; height:100%; background-color:Lime;">
<div style="width:75 px; height:75px; float:right;">
<asp:ImageButto n ID="MemberPhoto " runat="server" Width="75px"
Height="75px" />
</div>
<asp:Label ID="lblHeader" runat="server" Text=""></asp:Label>
<asp:LinkButt on ID="lbkLinkToMe ssage" 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(ob ject sender, EventArgs e)
{
HiddenField hiddenField = (HiddenField) e..Item.FindCon trol("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******@fitzm e.comwrote in message
news:uE******** *****@TK2MSFTNG P04.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.NO SPAMwrote in message
news:OF******** ******@TK2MSFTN GP02.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:Repeate r ID="rptMessages " runat="server" DataSourceID="o dsMessage"
OnItemDataBoun d="Display_Mess ages">
<HeaderTemplat e><table width="100%"></HeaderTemplate>
<ItemTemplat e>
<asp:HiddenFiel d ID="fhId" runat="server" />
<tr>
<td >
<div style="width:10 0%; height:100%; background-color:Lime;">
<div style="width:75 px; height:75px; float:right;">
<asp:ImageButto n ID="MemberPhoto " runat="server" Width="75px"
Height="75px " />
</div>
<asp:Label ID="lblHeader" runat="server" Text=""></asp:Label>
<asp:LinkButt on ID="lbkLinkToMe ssage" runat="server"
OnCommand="Ope n_Message">Repl y</asp:LinkButton>
<asp:Literal ID="ltMessage" runat="server"> </asp:Literal>
</div>
</td>
</tr>
</ItemTemplate>
<FooterTemplat e></table></FooterTemplate>

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

Any suggestions?`

Jeff


Oct 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
5982
by: Alex | last post by:
Is there any way to delete the value of a html hidden input field from code-behind? I use an html hidden input to store an array of data. I collect this data using Request.Form or Request.Params. After I use it, I want to force the deletion of it, so a user cannot hit their refresh button on their browser and trigger the same events that just...
2
1531
by: André | last post by:
Hi, I want to pass a integer value to client-side via a hiddenfield created in the aspx (HiddenField1) dim myvalue as integer myvalue=5 HiddenField1=myvalue When fetching in Javascript, the value is of type string.
5
6839
by: james.calhoun | last post by:
I feel like this should be really easy... I want a hidden field in a form to have its value defined when someone clicks on a link. So if they click on link "A" the value of the hidden field becomes "A", while if they click "B" the value of hidden field becomes "B" Help?
3
1962
by: sklett | last post by:
I've added a HiddenField control to my page and some javascript to show it's value in an alert box when a button is pressed. The value that is displayed in the alert box is correct, but when I post the form the value for the HiddenField control is empty. I'm pretty new to ASP.net so I'm not really sure what could cause this. I'm using...
0
1730
by: =?Utf-8?B?cGI2NDgxNzQ=?= | last post by:
We have been having this problem for months and always assumed it was because of our somewhat complicated setup. I have just spent almost all of today making this into a simple example that can be easily reproduced and it seems like a major .NET flaw/limitation that I was hoping you could explain to me as it is really frustrating me. I just...
4
4570
by: bushi | last post by:
hi ! i have following code to display some text on a web form,after getting it from database. <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <asp:LinkButton ID="links" runat="server" Text='<%# Eval("links") %>' OnClick="LinkButton1_Click"></asp:LinkButton><br />
1
3434
by: RSH | last post by:
I have a situation where I have a user control (Called TopOrangeMenu) that has an Hidden HTML Field called "txtU" I am trying to get at the value of that hidden field control from within the User Control. Hidden Field Control as it apears in the HTML of the User Control: <INPUT id="txtU" type="hidden" runat="server"> Trace Output...
3
1371
by: KBTibbs | last post by:
I've got an ASP.NET page that's doing some moderate data calculations based on user input. I've got a button that onclick runs a javascript function to pop open a new window and display the data I want it to have. After hacking my way through several strange problems, I've got it working for the most part. I'm down to only one problem: The...
0
1045
by: loginarpit | last post by:
I am dynamically creating a row of elements including a HiddenField. In a client-side function I am updating the value of this HiddenField. its ok till now. Now a button click causes a postback and the row of dynamically created elements ( including a HiddenField) is recreated. But the value of HiddenField is not restored as it is restored by...
0
7805
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7815
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8098
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6452
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3740
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2243
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.