Click here to Skip to main content
15,891,424 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I have a hidden field like this
ASP.NET
<div class="col-xs-12 pull-right" style="text-align: right;">
                                       <asp:UpdatePanel ID="udpAjaxTimer" runat="server">
                                           <ContentTemplate>
                                               <asp:Label ID="Label1" runat="server" Text="TimeLeft:" Font-Size="10pt"></asp:Label>
                                               <asp:Label ID="Label2" runat="server" Text="" Font-Bold="true" Font-Size="10pt"></asp:Label>
                                                <asp:HiddenField ID="hdnUsedTime" runat="server" />
                                           </ContentTemplate>
                                           <Triggers>
                                               <asp:AsyncPostBackTrigger ControlID="Timer1" />
                                           </Triggers>
                                       </asp:UpdatePanel>
                                       <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
                                       </asp:Timer>
                                   </div>

Now i want to access the value of that hidden field using java script
can any one please tell me how to solve this?

thanks in advance
(Keerthi Kumar)
Posted
Updated 28-Apr-15 20:59pm
v3
Comments
KaushalJB 29-Apr-15 3:01am    
How are you assigning value to hdnUsedTime ? and after accessing the value what operation you need to perform ?
Keerthi Kumar(Andar) 29-Apr-15 3:04am    
am assigning the value through c# code behind. after accessing that i want to pass that value to ajax method call
var hdnValue = $("input[id$='hdnUsedTime']").val();
this is giving Undefined

1 solution

As long as you can uniquely identify an element - you can access it (the fact that it is a hidden field is irrelevant, as it is only for the visual part is hidden, but still there in the DOM)...
ASP.NET HiddenField renders to a HTML element of input with type set to hidden...The only problem is that the id can be extended by the ASP.NET rendering engine...Learn about it here[^]...

Now the way to get the generated id from client side code is using inline server tags...

Plain JS
JavaScript
var el = document.getElementById('<%= hdnUsedTime.ClientID %>');

JQuery
JavaScript
var el = $('#<%= hdnUsedTime.ClientID %>');

The <%= hdnUsedTime.ClientID %> part will be translated to the real, client-side id of the element when page got rendered...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900