如何从jQuery的变量传递给后面的代码(C#)? [英] How to pass variable from jquery to code behind (C#)?

查看:114
本文介绍了如何从jQuery的变量传递给后面的代码(C#)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的代码,但它不工作(代码隐藏得空字符串):
`

Here is my code, but it doesn't work (code behind gets empty string): `

<head id="Head1" runat="server">
<title>Pass Javascript Variables to Server</title>
     <script type="text/javascript">             // Second Step
         function f() {
             $("[id$='inpHide']").val("My JavaScript Value");

         }
    </script>
</head>

<body onload="SetHiddenVariable()">
    <form id="form1" runat="server">
    <div>  
        <input id="inpHide" type="hidden" runat="server" />  
        <asp:Button ID="btnJSValue" Text="Click" runat="server" OnClientClick="f"/>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>



`

`

推荐答案

有几个问题在你的代码。而在的OnClientClick 调用˚F函数括号人失踪,如果该元素的ID是你可以使用id选择它与

There were couple of issues in your code. The parenthesis were missing while calling f function in onClientClick and if the element has id you can just use the id to select it with #

<head id="Head1" runat="server">
<title>Pass Javascript Variables to Server</title>
     <script type="text/javascript">             // Second Step
         function f() {
             $("input[id*='inpHide']").val("My JavaScript Value");
         }
    </script>
</head>

<body>
    <form id="form1" runat="server">
    <div>  
        <input id="inpHide" type="hidden" runat="server" />  
        <asp:Button ID="btnJSValue" Text="Click" runat="server" OnClientClick="f()"/>
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </div>
    </form>
</body>

这篇关于如何从jQuery的变量传递给后面的代码(C#)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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