Asp.Net Get Screen Width

后端 未结 4 1577
囚心锁ツ
囚心锁ツ 2021-01-03 11:00

How can I get the screen width on the server side in an Asp.net (C#) project?

相关标签:
4条回答
  • 2021-01-03 11:24

    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"];
    
    0 讨论(0)
  • 2021-01-03 11:33

    Use code below

    int width = (Request.Browser.ScreenPixelsWidth) * 2 - 100;
    int height = (Request.Browser.ScreenPixelsHeight) * 2 - 100;
    
    0 讨论(0)
  • 2021-01-03 11:40

    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.

    0 讨论(0)
  • 2021-01-03 11:43

    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

    var ScreenPixelsHeight  = window["innerHeight"];  
    var ScreenPixelsWidth  = window["innerWidth"];
    var JSLink = "http://www  +  "&ScreenPixelsHeight="+ScreenPixelsHeight+
    "&ScreenPixelsWidth="+ScreenPixelsWidth;
    
    0 讨论(0)
提交回复
热议问题