我如何访问asp.net hidenfield并将值存储到hidenfield javascript / asp.net [英] how can i access a asp.net hidenfield and store a value to hidenfield javascript/asp.net

查看:133
本文介绍了我如何访问asp.net hidenfield并将值存储到hidenfield javascript / asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。

可以帮助我如何在javascript上将值存储到HidenField。

解决方案

你可以打开查看文件浏览器。并在浏览器中查看源代码。您会发现隐藏字段ID与您的aspx文件中的字段ID不同。 IT将以此格式显示(


Wizard1


TextBox2)如果您在另一个服务器端控件中具有服务器端控件。您可以使用ControlID.ClientID.Here属性获得正确的控件ID,下面是一个演示:



<!DOCTYPE html PUBLIC"  -  // W3C // DTD XHTML 1.0 Transitional // EN" " HTTP://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

< html xmlns =" http://www.w3.org/1999/xhtml">
< head runat =" server">
< title>< / title>
< / head>
< body onload =" document.getElementById('<%= HiddenField1.ClientID%>')。value ='Denny.Dong';">
< form id =" form1" RUNAT = QUOT;服务器">
< div>

< / div>
< asp:TextBox ID =" TextBox1" RUNAT = QUOT;服务器">< / ASP:文本框>
< asp:HiddenField ID =" HiddenField1" RUNAT = QUOT;服务器"值= QUOT; sfdsfsdf" />
< a href ="#" onclick =" alert(document.getElementById('<%= HiddenField1.ClientID%>')。value)" >显示HF数据< / a>

< asp:Button ID =" Button1" RUNAT = QUOT;服务器"文本= QUOT;按钮和QUOT; />

< / form>
< / body>
< / html>


<!DOCTYPE html PUBLIC"  -  // W3C // DTD XHTML 1.0 Transitional // EN" " HTTP://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

< html xmlns =" http://www.w3.org/1999/xhtml">
< head runat =" server">
< title>< / title>
< script type =" text / javascript"语言= QUOT; JavaScript的">
function setdata(){
document.getElementById("<%= HiddenField1.ClientID%>")。value ='Denny.Dong';
}
函数showDa(){
alert(document.getElementById("<%= HiddenField1.ClientID%>")。value);
}
< / script>
< / head>
< body onload =" setdata()">
< form id =" form1" RUNAT = QUOT;服务器">
< div>

< / div>
< asp:TextBox ID =" TextBox1" RUNAT = QUOT;服务器">< / ASP:文本框>
< asp:HiddenField ID =" HiddenField1" RUNAT = QUOT;服务器"值= QUOT; sfdsfsdf" />
< a href ="#"的onclick = QUOT; showDa()" >显示HF数据< / a>

< asp:Button ID =" Button1" RUNAT = QUOT;服务器"文本= QUOT;按钮和QUOT; />

< / form>
< / body>
< / html>



抱歉,我找不到我发布的代码。


Hi.

could any one help me how to store a value to a HidenField at javascript.

解决方案

You can open View the file in browser.And view the source code in the browser. you will find the Hidden field ID is not the same as it in your aspx file. IT will display in this formart(

Wizard1


TextBox2)  if you have the serverside control in another server side control. You can get the correct control id with the attribute ControlID.ClientID.Here is a demo below:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body onload="document.getElementById('<%=HiddenField1.ClientID %>').value='Denny.Dong';">
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:HiddenField ID="HiddenField1" runat="server" Value="sfdsfsdf" />
    <a href="#" onclick="alert(document.getElementById('<%=HiddenField1.ClientID %>').value)" >Show HF Data</a>
    
    <asp:Button ID="Button1" runat="server" Text="Button" />
    
    </form>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript">
        function setdata() {
            document.getElementById("<%=HiddenField1.ClientID %>").value = 'Denny.Dong';
        }
        function showDa() {
            alert(document.getElementById("<%=HiddenField1.ClientID %>").value);
        }
    </script>
</head>
<body onload="setdata()">
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:HiddenField ID="HiddenField1" runat="server" Value="sfdsfsdf" />
    <a href="#" onclick="showDa()" >Show HF Data</a>
    
    <asp:Button ID="Button1" runat="server" Text="Button" />
    
    </form>
</body>
</html>

Sorry,I couldn't find the code i have posted.


这篇关于我如何访问asp.net hidenfield并将值存储到hidenfield javascript / asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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