C# Asp.Net 获取屏幕宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14746564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Asp.Net Get Screen Width
提问by John
How can I get the screen width on the server side in an Asp.net (C#) project?
如何在 Asp.net (C#) 项目中获取服务器端的屏幕宽度?
采纳答案by TGlatzer
You could read it with javascript and submit the results to the server.
A server-side-only solution can not exist, since html does not submit such data automatically in requests.
您可以使用 javascript 读取它并将结果提交给服务器。
仅服务器端的解决方案是不存在的,因为 html 不会在请求中自动提交此类数据。
回答by flap13
Place this on your form:
把它放在你的表格上:
<input type="hidden" value=""
name="clientScreenHeight" id="clientScreenHeight" />
<input type="hidden" value=""
name="clientScreenWidth" id="clientScreenWidth" />
This is onload script:
这是加载脚本:
$(document).ready(function () {
$("#clientScreenWidth").val($(window).width());
$("#clientScreenHeight").val($(window).height());
});
This is server side code:
这是服务器端代码:
string height = HttpContext.Current.Request.Params["clientScreenHeight"];
string width = HttpContext.Current.Request.Params["clientScreenWidth"];
回答by Yitzhak Weinberg
to get the Characters
获取字符
Request.Browser.ScreenCharactersWidth
Request.Browser.ScreenCharactersHeight
to get the Resolution
获得决议
you need to send the data from client side with javascript or jquery i use this code its good the work
您需要使用 javascript 或 jquery 从客户端发送数据我使用此代码很好的工作
var ScreenPixelsHeight = window["innerHeight"];
var ScreenPixelsWidth = window["innerWidth"];
var JSLink = "http://www + "&ScreenPixelsHeight="+ScreenPixelsHeight+
"&ScreenPixelsWidth="+ScreenPixelsWidth;
回答by bilal chaudhari
Use code below
使用下面的代码
int width = (Request.Browser.ScreenPixelsWidth) * 2 - 100;
int height = (Request.Browser.ScreenPixelsHeight) * 2 - 100;