ASP.NET在Javascript中设置hiddenfield值 [英] ASP.NET set hiddenfield a value in Javascript

查看:116
本文介绍了ASP.NET在Javascript中设置hiddenfield值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在Javascript中设置hiddenField的值。有人可以告诉我怎么做吗?

I don't know how to set the value of a hiddenField in Javascript. Can somebody show me how to do this?

Javascript:

Javascript:

document.getElementById('hdntxtbxTaksit').value = "";

HTML:

<asp:HiddenField ID="hdntxtbxTaksit" runat="server" Value="" Visible="false">   </asp:HiddenField>




错误:无法获取属性值\'值\':对象为空或未定义

error : "Unable to get value of the property \'value\': object is null or undefined"


推荐答案

在ASP之前。净4.0

ClientID

获取在中生成的客户端ID使用母版页的页面。由于Master页面是UserControl类型,它将拥有自己的Id,它将页面视为Child控件,并生成一个不同的id,其前缀如 ctrl _

Get the client id generated in the page that uses Master page. As Master page is UserControl type, It will have its own Id and it treats the page as Child control and generates a different id with prefix like ctrl_.

这可以通过在页面中使用<%= ControlName.ClientID%> 来解决,并且可以分配给任何字符串或者可以在以后引用的javascript变量。

This can be resolved by using <%= ControlName.ClientID %> in a page and can be assigned to any string or a javascript variables that can be referred later.

var myHidden=document.getElementById('<%= hdntxtbxTaksit.ClientID %>');




  • 如果您使用母版页,Asp.net服务器控件ID将会有所不同。

  • ASP.Net 4.0 +

    ClientIDMode属性

    使用此属性可以控制您为自己生成ID的方式。对于您的案例设置,页面级别的 ClientIDMode =static将解决问题。同样的事情也可以在控制级别应用。

    Use this property to control how you want to generate the ID for you. For your case setting ClientIDMode="static" in page level will resolve the problem. The same thing can be applied at control level as well.

    这篇关于ASP.NET在Javascript中设置hiddenfield值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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