asp.net传递值从JS / jQuery来code后面的C# [英] asp.net passing values from JS/jquery to code behind c#
本文介绍了asp.net传递值从JS / jQuery来code后面的C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我曾尝试每在code中的aspx页面从JS脚本发送screen.width vlaue到C#和落后的同时,可能的方式我可以看到screen.width被正确分配它从来没有被分配到我的隐藏字段值。
I have tried "every" possible way of sending the screen.width vlaue from the JS script on the aspx page to the c# in the code behind and while I can see the screen.width being assigned correctly it never gets assigned to my hidden field value.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:HiddenField ID="hiddenfield" runat="server" />
<script type="text/javascript" language="javascript">
$(function(){
$('#hiddenfield').val(screen.width);
});
</script>
other content
</asp:Content>
和背后的code:
protected void btnChartGo_Click(object sender, EventArgs e)
{
string s = hiddenfield.Value;
}
不管是什么我试着S始终,
No matter what I try s is always ""
蹊跷的上面,每个人似乎都在做这样说,这和它的作品?
Something wrong with the above, everyone seems to be doing it like that and it works?
推荐答案
这应该得到正确的选择:
This should get the right selector:
$('#<%= hiddenfield.ClientID %>').val(screen.width);
这篇关于asp.net传递值从JS / jQuery来code后面的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文