i have followed the answer written here
but some how i am not able to get the values in my code behind.
below is my code sample
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</script>
<script type="text/javascript">
$(document).ready(function () {
$("#width").val() = $(window).width();
$("#height").val() = $(window).height();
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="width" runat="server" />
<asp:HiddenField ID="height" runat="server" />
<asp:ImageButton ID="MySearchButton" runat="server" Height="38" ImageUrl="~/Images/search-button-without-text-md.png" OnClick="MySearchButton_Click" />
</form>
</body>
</html>
and this is my code behind
protected void MySearchButton_Click(object sender, ImageClickEventArgs e)
{
var BrowserWidth = width.Value;
var BrowserHeight = height.Value;
}
but some how i am not able to get the height and width of the browser. the values are empty. can some one suggest me what i am doing wrong here.
Try http://api.jquery.com/val/#val2
$(document).ready(function () {
$("#width").val($(window).width());
$("#height").val($(window).height());
});
$.prototype.val
acts as a hybrid get/set ie getter when called w/o argument and setter w/ argument. $inst.val()
- get field value. $inst.val(value)
- set field value.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.