问题
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.
回答1:
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.
回答2:
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
回答3:
string hiddenFieldValue = rssLink.Value;
回答4:
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
来源:https://stackoverflow.com/questions/22089285/get-hidden-field-value-in-code-behind