如何使用javascript访问更新面板中存在的隐藏字段值? [英] How to access hidden Field Value present inside update panel using javascript ?

查看:59
本文介绍了如何使用javascript访问更新面板中存在的隐藏字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



我有一个像这样的隐藏字段

 <   div     class   =  col-xs-12 pull-right    style   =  text -align:right; >  
< asp:UpdatePanel ID = udpAjaxTimer runat = server >
< ContentTemplate >
< asp :标签 ID = Label1 runat = server 文字 = TimeLeft: 字体大小 = 10pt > < / asp:Label >
< asp:Label ID = Label2 runat = server 文字 = 字体粗体 = true 字体大小 = 10pt > < / asp:Label >
< asp:HiddenField ID = hdnUsedTime runat = server / >
< span class =code-keyword><
/ ContentTemplate >
< 触发器 >
< asp:AsyncPostBackTrigger ControlID = Timer1 / >
< / Triggers >
< / asp:UpdatePanel >
< asp:计时器 ID = Timer1 runat = server 间隔 = 1000 OnTick = Timer1_Tick >
< / asp:Timer >
< / div >



现在我想使用该隐藏字段的值来访问java脚本

任何人都可以告诉我如何解决这个问题?



提前感谢

(Keerthi Kumar)

解决方案

只要你可以唯一地识别一个元素 - 你可以访问它(它是一个隐藏字段的事实是无关紧要的,因为它只是为了视觉部分是隐藏的,但仍然存在于DOM中... ...

ASP.NET HiddenField呈现给输入的HTML元素,类型设置为隐藏...唯一的问题是id可以通过ASP.NET呈现引擎进行扩展...了解它这里 [ ^ ] ...



现在获得t的方式他从客户端代码生成id使用内联服务器标签...



普通JS

<前lang =Javascript> < span class =code-keyword> var el = document .getElementById(' < span class =code-string><%= hdnUsedTime.ClientID%>');



JQuery

  var  el = 


' #<%= hdnUsedTime.ClientID%>');



<%= hdnUsedTime.ClientID%>当页面被渲染时,part将被转换为元素的真实客户端id ...


Hi Experts,

I have a hidden field like this

<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)

解决方案

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

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


JQuery

var el =


('#<%= hdnUsedTime.ClientID %>');


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


这篇关于如何使用javascript访问更新面板中存在的隐藏字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆