FeliceM
FeliceM

Reputation: 4199

Get hidden field value in code behind

How can I get the value of the hiddenfield in code behind?

 <telerik:RadRotator ID="RadRotator1" RotatorType="AutomaticAdvance" ScrollDirection="Up"
                ScrollDuration="4000" runat="server" Width="714"
                ItemWidth="695" Height="260px" ItemHeight="70" FrameDuration="1" InitialItemIndex="-1"
                CssClass="rotator">
                <ItemTemplate>
                    <div class="itemTemplate" style="background-image: url('IMAGES3/<%# this.GetDayOfWeek(XPath("pubDate").ToString()) %>.png');">
                        <div class="dateTime">
                            <div class="time">
                                <%# (this.GetTimeOnly(XPath("pubDate").ToString())) %>
                            </div>
                            <div class="date">
                                <%# (this.GetDateOnly(XPath("pubDate").ToString()))%>
                            </div>
                        </div>
                        <div class="title">
                            <span>
                                <%# System.Web.HttpUtility.HtmlEncode(XPath("title").ToString())%>
                            </span>
                        </div>
                        <div class="buttonDiv">
                            <asp:Button ID="Button1" class="button" runat="server" Text="View" OnClientClick="OnClick"  />
        THIS HIDDENFIELD >>>>> <asp:HiddenField id="rssLink" runat="server" value='<%= System.Web.HttpUtility.HtmlEncode(XPath("link").ToString()%>' />

                        </div>
                        <div class="description">
                            <span>
                                <%# System.Web.HttpUtility.HtmlEncode(XPath("description").ToString())%>
                            </span>
                        </div>
                    </div>
                </ItemTemplate>
            </telerik:RadRotator>

The hidden field is inside a RadRotator and I am battling to get the value of it in code behind.

Upvotes: 2

Views: 42130

Answers (4)

Rami
Rami

Reputation: 7290

If the Hidden field has the runat="server" attribute then you should be able to access it from the server side using 2 ways:

1- using the value property.

2- using Request.Forms["hiddenFieldName"]

Check this link

Upvotes: 1

Liath
Liath

Reputation: 10191

You can use it's Value property

var value = this.rssLink.Value;

Edit: for the telerik control it looks like you'll need to use FindControl on the Databind - there's an article here.

Upvotes: 6

Microsoft DN
Microsoft DN

Reputation: 10010

string hiddenFieldValue = rssLink.Value;

Upvotes: 2

Sloth
Sloth

Reputation: 172

when you write something like that in your aspx file you will see that in the designer file you've got a generated property with as name the id of the field you used.

So in the code behind you can use this property because the classes are partial

var value = this.rssLink.Value;

like said before

Upvotes: 2

Related Questions