Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi all
how can we calculate client browser window width and hight
an example will be deeply appreciated
thanks
Posted

1 solution

you can find in this tutorial

http://www.java-samples.com/showtutorial.php?tutorialid=1015[^]

if you want to get this in codebehind

if you want to use this clearly please dont forget add script jquery and ScriptManagerin page

in your html line put this in body

ASP.NET
<input type="hidden" id="inptWidth"  runat="server" />
<input type="hidden" id="inptHeight" runat="server" />


your script
JavaScript
<script type="text/javascript">

    // this is a jquery syntax
    $(document).ready(function() {
        var inptWidth = $get('<%=inptWidth.ClientID %>');// you must to use in page ScriptManager
        var inptHeight = $get('<%=inptHeight.ClientID %>');
        inptWidth.value = window.innerWidth;
        inptHeight.value = window.innerHeight;
    });

</script>


and this my anybuttons click event

C#
protected void btnControl_Click(object sender, EventArgs e)
        {           
            string val = inptWidth.Value;           
        }


dont forget you cant do this in load of page. because clientside loading occuring after server-side loading.
 
Share this answer
 
v3
Comments
mehdilahori 26-May-12 11:08am    
hi dain
i read this article before
thanks for reply
actually i want to calculate browser width and height in asp.net using c#
thanks
Dain Ucak 26-May-12 13:35pm    
do you mean you want to calculate browsers width and height in codebehind of an asp.net page?
mehdilahori 27-May-12 2:15am    
yes dain
i want to calculate browser window inner width and height but dont know about the code behind
thanks
Dain Ucak 27-May-12 5:28am    
you can do this. set in javascript innerWidth and innerHeight property to any serverside control, Call this control in codebehind.
i will improve my solution. check it
Vijaykumar Vadnal 30-May-12 2:27am    
Dain, awesome soln

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900