开发者

How to retrieve a value from jquery in C# user control?

I have a visitorID variable in ToDo function in external javascript.

I want to assign its' value in a user control. Front End Code:

<asp:HiddenField ID="hidVisitorID" runat="server" Value="-1"/>

<script type="text/javascript">

$j('#<%= hidVisitorID.ClientID %>').val(ToDo.visitorID);

</script>

In the back end it says, that hidVisitorID.Value is null (or -1 in this case). How do I assign value 开发者_Go百科from jquery variable to hidVisitorID ?


Try this code:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="my_TO_DO.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        alert('my todo varname is: ' + ToDo.variableName);
        $('#<%= hidVisitorID.ClientID %>').val("foobar");
    });
</script>


 <asp:HiddenField ID="hidVisitorID" runat="server" Value="-1"/>

 <asp:Button Text="sub" runat="server" onclick="Click" />

When you click the button, it'll post back.

protected void Click(object sender, EventArgs e)
{
    string valFromHidden = hidVisitorID.Value;
   //valFromHidden is now foobar
}    

Ensure your jQuery reference is ABOVE your other .js reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜