detect mobile device orientation from code behind. RRS feed

  • Question

  • User944339287 posted

    dear all,

    currently i using this way to decide show how many items a row.. but it's not perfect if mobile device switch to landscape view..

    any idea? how do i detect orientation from code behind? tq

            If Request.Browser.IsMobileDevice = True Then
                If Request.UserAgent.ToLower().Contains("ipad") = True Then
                    Me.lv_Product.GroupItemCount = 4
                    Me.lv_Product.GroupItemCount = 2
                End If
                Me.lv_Product.GroupItemCount = 4
            End If

    Saturday, May 7, 2016 1:22 AM

All replies

  • User-286291038 posted

    Hi Kengkit,

    It is better to detect device orientation from front end and using css media queries accordingly. Some references,



    Monday, May 9, 2016 1:35 PM
  • User944339287 posted

    thanks! but the reason y i need to detect from code behind is becoz i wanna change PageNumber accordingly.

    if landscape.. 4 items per row.. if portrait will be 2 items per row.

    Tuesday, May 10, 2016 3:53 AM
  • User2036436350 posted

    Hi kengkit,

    I would not recomend performing server side operations every-time the orientation is changed withing the client. This will result in your application to be slow to load every time the user changes his/her orientation. Hence as recomended by Nataraj, you are better off performing this feature within the client side that making server-side calls each time the user changes his her orientation. 

    Happy Coding!

    Tuesday, May 10, 2016 5:50 AM