I want to access user screen resolution from server side.
For this I have asp hidden control:
<asp:HiddenField runat="server" ID="hdnScreenResolution" />
Which actually rendering on page:
<input type="hidden" name="ctl00$MainContent$hdnScreenResolution" id="MainContent_hdnScreenResolution" />
I use javascript function to insert value in it:
$(document).ready(function () {
var width = screen.width;
var height = screen.height;
var hiddenScreenResolution = document.getElementById('<%= hdnScreenResolution.ClientID
%>');
hiddenScreenResolution.value = "asass";
});
And it is on page source code:
$(document).ready(function () {
var width = screen.width;
var height = screen.height;
var hiddenScreenResolution = document.getElementById('MainContent_hdnScreenResolution');
hiddenScreenResolution.value = "asass";
});
On server side I check hidden value on Page_Load():
protected void Page_Load(object sender, EventArgs e)
{
var hiddenValue = hdnScreenResolution.Value;
}
But value appears to be empty string. Using jquery does not help.
Inserting directly: document.getElementById('<%= hdnScreenResolution.ClientID %>').value = "asdasd"; does not help.
What the problem can be?
P.S. I suppose that I catching screen resolution on document.ready is too late.
And javascript fires after page was unloaded. So no change to catch it on initial request.
Looking forward for an answer.