将C#属性读入JQuery代码

Rus*_*ark 6 c# asp.net jquery properties

我正在尝试从我的代码隐藏文件中读取C#属性的值到一些JQuery脚本(见下文).我编写的JQuery选择器访问ASP.Net GridView,然后访问gridview中的CheckBox字段.每当选中或取消选中复选框时,代码都会被命中,但我需要从后面的代码中访问C#属性,以根据属性的值采取适当的操作.

    $(".AspNet-GridView-Normal > td > input").click(function() {

        //Need to access the C# property here

        //Take action here based on the value of the C# property

     });
Run Code Online (Sandbox Code Playgroud)

Mar*_*nof 12

这可能是显而易见的,但是在执行jQuery代码的客户端上不存在背后的代码.您可以做的是将属性的值分配给服务器端的隐藏字段,以便在需要在客户端使用jQuery进行检查时,它将可用.因此,您可以在客户端执行以下操作.

标记:

<asp:HiddenField ID="hfValueINeedToKnow" runat="server"/>
Run Code Online (Sandbox Code Playgroud)

代码背后:

hfValueINeedToKnow.Value = <some value>;
Run Code Online (Sandbox Code Playgroud)

jQuery的:

$("#<%= hfValueINeedToKnow.ClientID %>").val();
Run Code Online (Sandbox Code Playgroud)

您可能需要进行一些小的更改以支持网格中每一行的值,但希望这可以解释一般的想法.