0

我需要在服务器端获取用户屏幕分辨率并根据分辨率调整控件的大小。

我有asp:HiddenField我想存储分辨率的地方。

<asp:HiddenField runat="server" ID="hdnScreenResolution" />

我有提交分辨率的 jquery ajax 调用:

 $(document).ready(function () {
      width = screen.width;
      height = screen.height;
      $.ajax({
         url: "Questionnaire.aspx/WindowResolutionSet",
         data: "{ 'width': '" + width + "', 'height' : '" + height + "'}",
         type: "POST",
         contentType: "application/json; charset=utf-8",
         sucess: function (msg) { alert("it works"); },
         error: function () { alert("error"); }
     });
 });

和它的网络方法:

    [WebMethod]
    public static bool WindowResolutionSet(string width, string height)
    {
        return true;
    }

从 WindowResolutionSet 我无法访问页面上的服务器控件。

并且sucess: function (msg) { alert("it works");不开火。

我想填充widthheight打开sucess,然后从中访问它,Page_Load()sucess不会触发。error也不执行。

必须有更有效的方法,但我不知道它=/

4

1 回答 1

3

这些值可以使用HttpCapabilitiesBase.ScreenPixelsWidthHttpCapabilitiesBase.ScreenPixelsHeight直接访问。

例子:

 var clientSize = new { 
      X = Page.Request.Browser.ScreenPixelWidth, 
      Y = Page.Request.Browser.ScreenPixelHeight
      };
 SomeMethod(clientSize.X, clientSize.Y);
于 2013-01-10T14:10:27.227 回答