Introduction
This article explains how to change Grid Size dynamically based on screen resolution.
A condition is often put before the developers that the Grid size should change depending on the Screen Resolution of the user so that the user can easily access the Website at any Screen Resolution. Today I will show you something by which this problem will be solved and that too is in a simpler way.
Let's see the procedure required to create such an application.
Step 1. First of all, I worked on a webpage on which a JavaScript-ready function is created in which the height will be sent to the WebService method of a WebService. Its code is as follows.
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
var windowHeight = $(window).height();
UIService.SaveNewHeight(windowHeight, OnCompleted);
});
function OnCompleted() {}
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/UIService.asmx" />
</Services>
</asp:ScriptManager>
</asp:Content>
Here you can see that after creating the Ready function I had passed the reference of a WebService to which the WebService method was passed.
Step 2. The WebService method will be used to store the window height in a Session Variable, but first check whether your project has a WebService, if not then right-click on your WebSite/Project and choose "Add New Item".

Now in this WebService, the Webservice method will be used to pass the window height in a Session variable.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class UIService : System.Web.Services.WebService
{
public UIService()
{
}
[WebMethod(EnableSession = true)]
[ScriptMethod()]
public void SaveNewHeight(string height)
{
HttpContext.Current.Session["WindowHeight"] = height;
}
}





Join the conversation! Your thoughts help the community grow.