读的C#属性为JQuery的code [英] Reading C# property into JQuery code

查看:124
本文介绍了读的C#属性为JQuery的code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的C#属性的从后面的文件我的code值到一些jQuery脚本(见下文)。我已经写了jQuery选择器访问GridView控件内的ASP.Net的GridView,然后一个复选框字段。每当一个复选框被选中或取消检查code被击中,但我需要从code访问的C#属性后面根据属性的值来采取适当的行动。

  $(ASPNET-GridView控件 - 正常方式> TD>输入)。点击(函数(){        //这里需要访问C#属性        //采取行动这里基于C#属性的值     });


解决方案

这可能说明明显,但code后面不会对您的jQuery的code所执行的客户端存在。你可以做的是属性值分配给隐藏字段在服务器端,这样当你需要使用jQuery检查它在客户端上这将是可用。所以,你可以做在客户端下面。

标记:

 < ASP:HiddenField ID =hfValueINeedToKnow=服务器/>

code背后:

  hfValueINeedToKnow.Value =<一些价值取代;

jQuery的:

  $(#<%= hfValueINeedToKnow.ClientID%GT;)。VAL();

您可能需要进行一些小的改动,以支持网格的每一行的值,但希望这解释了总体思路。

I'm trying to read the value of a C# property from my code behind file into some JQuery script (see below). The JQuery selector I've written accesses an ASP.Net GridView and then a CheckBox field within the gridview. Whenever a checkbox is checked or un-checked the code is hit, but I need to access the C# property from the code behind to take the appropriate action based on the value of the property.

    $(".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

     });

解决方案

This may be stating the obvious, but the code behind doesn't exist on the client side where your jQuery code is executing. What you could do is assign the value of the property to a hidden field on the server side so that when you need to check it with jQuery on the client side it will be available. So you might do the following on the client side.

Markup:

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

Code Behind:

hfValueINeedToKnow.Value = <some value>;

jQuery:

$("#<%= hfValueINeedToKnow.ClientID %>").val();

You might need to make some minor changes to support a value for each row of the grid, but hopefully this explains the general idea.

这篇关于读的C#属性为JQuery的code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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