简体   繁体   English

如何从 asp.net 中的 java 脚本代码(客户端)访问隐藏字段值 c#

[英]How to access hidden field value from java script code(Client side) in asp.net c#

I have defined hidden field in.aspx page(ui)我在.aspx 页面(ui) 中定义了隐藏字段

 <asp:HiddenField ID ="hdnExport" runat="server" />

Set the value in the following code (java script)在以下代码(java 脚本)中设置值

$(document).ready(function () {
            $("#btn_FinalConfirmOK").on("click", function (event) {
                alert("clicked");
                //document.getElementById("hdnExport").value = "yes";
                $('#hdnExport').val("yes");
               
                alert($('#hdnExport').val());

                document.getElementById('hdnExport').value = "yes";
                //alert("yes");
            });
        });

Then accessing hidden field value in aspx.cs code is given below,然后访问 aspx.cs 代码中的隐藏字段值如下所示,

string exportValue = Convert.ToString(hdnExport.Value);
        string exp = hdnExport.Value.ToString();
        var val = this.hdnExport.Value;
        string latitudeValue = Request.Form[hdnExport.Value];

Tried with different ways.尝试了不同的方法。 but i didn't get value from hidden field.但我没有从隐藏字段中获得价值。 how to solve this issue如何解决这个问题

By default, the rendered id will differ from the ID specified within C# ( hdnExport ).默认情况下,呈现的id将不同于 C# ( hdnExport ) 中指定的ID Therefore, ( #hdnExport ) is likely an invalid selector thus no value is set.因此,( #hdnExport ) 可能是无效的选择器,因此未设置任何值。

Try setting ClientIDMode="Static" on the HiddenField :尝试在HiddenField上设置ClientIDMode="Static"

 <asp:HiddenField ID ="hdnExport" ClientIDMode="Static" runat="server" />

This will ensure the hidden field is rendered with id as ID which would make #hdnExport valid.这将确保隐藏字段以id作为ID呈现,这将使#hdnExport有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在javascript中设置asp.net隐藏字段并访问c#代码后面的值 - how to set asp.net hidden field in javascript and access the value in c# code behind 尝试使用隐藏字段将值从ASP.NET JavaScript脚本传递给我的C#代码隐藏函数 - Trying to pass value from ASP.NET JavaScript script to my C# Code Behind function using Hidden Field 试图将值从ASP.NET JavaScript脚本传递到我的C#隐藏字段 - Trying to pass value from ASP.NET JavaScript script to my C# Hidden Field 如何在Asp.Net的Button click事件中将值从C#发送到Java脚本? - How to send value from C# to java script on Asp.Net's Button click event? 如何根据它的字段值设置行颜色。asp.net 中的客户端 - How to set a row color based on it's field value.from client side in asp.net 从客户端Java脚本在ASP.NET中调用服务器端事件处理程序 - Calling server side event handler in asp.net from client side java script 最好的方法是使用客户端Java脚本访问深度嵌入的asp.net控件的属性? - What is the best was to access a property of a deeply embedded asp.net control using client side java script? 从C#Asp.net后面的代码设置输入文本字段的值 - Set the value of input text field from code behind C# Asp.net 将代码从Java转换为C#/ ASP.NET - translating code from Java to C#/ASP.NET 客户端和服务器端的Asp.net C#加密/解密 - Asp.net C# Encryption/Decryption on Client and server Side
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM