Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > ASP.NET 4 General Discussion
|
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 25th, 2011, 11:55 AM
Authorized User
 
Join Date: Dec 2011
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
Default screen size of the browser OnInit()

I'm calculating the screen size of the browser and storing passing it to the server and i'm dynamically creating controls on the page OnInit() based on the sizes. But OnInit() on the USERCONTROL is getting fired before javascript function fires to calculate the screen size.... i need the browser size on Onit no matter what for my task .... Any ideas? please help mail to [email protected]
 
Old December 26th, 2011, 05:25 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can't do it like this. When you request a page, it runs at the server first. The generated HTML is then sent to the browser when you can run some JavaScript. This means that for a single request, OnInit always fires before any client side JavaScript.

You could use a two-step approach:

1. Render a normal page just once, let JavaScript collect the screen resolution and submit to the server.
2. Store the resolution in cookies or session variables or elsewhere and use that information for subsequent pages.

This way, you overcome your problem as you collect the info just once in a separate request once at the start of a user's visit.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen Size Jitender ASP.NET 3.5 Basics 3 October 13th, 2010 12:53 AM
Screen Size and Java Script srotondo Classic ASP Professional 5 December 20th, 2004 07:24 PM
Size of Screen cinest General .NET 2 October 8th, 2004 03:33 AM
changing text size on screen markhardiman Classic ASP Professional 4 August 31st, 2004 07:01 AM
Screen Size bmains VB.NET 11 June 28th, 2004 02:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.