Asp.Net获取屏幕宽度

Joh*_*ohn 3 c# asp.net

如何在Asp.net(C#)项目中获取服务器端的屏幕宽度?

TGl*_*zer 7

您可以使用javascript阅读它并将结果提交给服务器.
仅服务器端解决方案不存在,因为html不会在请求中自动提交此类数据.


fla*_*p13 7

把它放在你的表格上:

<input type="hidden" value=""
   name="clientScreenHeight" id="clientScreenHeight" />
<input type="hidden" value=""
   name="clientScreenWidth" id="clientScreenWidth" />
Run Code Online (Sandbox Code Playgroud)

这是onload脚本:

$(document).ready(function () {
    $("#clientScreenWidth").val($(window).width());
    $("#clientScreenHeight").val($(window).height());
});
Run Code Online (Sandbox Code Playgroud)

这是服务器端代码:

string height = HttpContext.Current.Request.Params["clientScreenHeight"];
string width = HttpContext.Current.Request.Params["clientScreenWidth"];
Run Code Online (Sandbox Code Playgroud)