473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Getting the Screen Resolution into VBScript throught ASP.Net2

I know this is re-hashing this old problem, I have looked at almost all of the questions regarding this one, and the responces to this. BUT I need to find a solution that will work.

BackGround

I have a custom ASP.Net 2 app that will be going out to selective clients to use, and I have need to grab the screen size settings, (much as I do not want to, I have little to no choice). I know that JavaScript can detect the screen settings on the clients side and I can get it to place the values into an asp:Label. I also know that this is only on the client side so the server side will not see it or read it.

Problem

So now how can I get the VBScript to grab what the Java script create, without saving a cookie on the clients system. I found one solution but it started to run into trouble after a few weeks of testing by a couple of people. So now I am looking for a way to pass values from a client side javascript to a server side vbscript that is 100% fool proof.

Note:

I know alot of you would say that it is foolish to design a web site for screen size and I would agree, but the choice is out of my hands. I have to get the screen size. Second I know I can design self adjusting style sheet files for a veriety of settings, but this option is not to be used, again the choice is out of my hands. So any positive help would be gratly accepted.
Feb 27 '07 #1
8 5187
jhardman
3,406 Expert 2GB
Get the value in javascript, then pass it back to the ASP through a form, or use javascript to re-write a link so the data is in the url. I don't think there is another way to do what you are asking, ASP only generates what is asked.

Jared
Feb 27 '07 #2
Thanks. So far all attempts to have the client side java script to store its results in anythin that can be posted back to the server have failed. I can get the Javascript to place the results into an object on a form, but the server just can not see it.

Any ideas on what I can do to get this info?
Feb 28 '07 #3
jhardman
3,406 Expert 2GB
you can use javascript to post the form as soon as it is entered. I'm not a javascript guru, but the code is something like this:
Expand|Select|Wrap|Line Numbers
  1. <input type="hidden" name="screenRes" onChange="this.form.post()">
  2.  
Hmm. I'm not sure onChange works unless the user changes it.

You can put it all in an onload command, first populate the hidden input, then post the form. I've posted forms through javscript before, I don't remember even getting errors. Do you need a code example?

Jared
Feb 28 '07 #4
jhardman
3,406 Expert 2GB
code is form.submit().

Here are two examples, the first sends the data through the URL, the second through a hidden form.
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>test page (saved as test.asp)</title>
  4. <script language="JavaScript">
  5. <!-- Begin
  6. function rP() {
  7.    var w = screen.width;
  8.    var h = screen.height;
  9.    var newURL = "test.asp?height="+h+"&width="+w;
  10.    window.location.href= newURL;
  11. }
  12. // END -->
  13. </script>
  14.  
  15. </head>
  16. <%
  17. if request("height") = "" then %>
  18. <body onLoad="rP()">
  19.  
  20. <%
  21. else %>
  22. <body>
  23. Height=<%=request("height")%><br>
  24. width=<%=request("width")%><br>
  25. <%
  26. end if %>
  27. </body>
  28. </html>
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>test page 2 (saved as test2.asp)</title>
  4. <script language="JavaScript">
  5. <!-- Begin
  6. function rP(inH, inW, frm) {
  7.    inH.value=screen.height;
  8.    inW.value=screen.width;
  9.    frm.submit();
  10. }
  11. // END -->
  12. </script>
  13.  
  14.  
  15. </head>
  16. <%
  17. if request("height") = "" then %>
  18. <body onload="rP(this.document.all.bob.height,
  19.  this.document.all.bob.width,
  20.  this.document.all.bob)">
  21. <form name="bob" action="test2.asp" method="post">
  22. <input type="hidden" name="height">
  23. <input type="hidden" name="width">
  24. </form>
  25.  
  26. <%
  27. else %>
  28. <body>
  29. Height=<%=request("height")%><br>
  30. width=<%=request("width")%><br>
  31. <%
  32. end if %>
  33. </body>
  34. </html>
Please let me know if it works.

Jared
Feb 28 '07 #5
I gave your sujestions a try but had no luck in a sample copy of a page of mine.

Here is what I was using. This was in the detectscreen.aspx page.

<script runat="server" language="C#">
public void Page_Load(Object sender, EventArgs e){
if (Request.QueryString["action"] != null) {
// store the screen resolution in Session["ScreenResolution"]
// and redirect back to login.aspx
//Session["ScreenResolution"]= Request.QueryString["res"].ToString();
Profile.ScreenResolution = Request.QueryString["res"].ToString();
Response.Redirect("~/Login.aspx");
}
}
// JavaScript code below will determine the user screen resolution and
// redirect to itself with action=set QueryString parameter
</script>
<HTML>
<BODY>
<script language="javascript">
res = "&res="+screen.width+"x"+screen.height
top.location.href="detectscreen.aspx?action=set"+r es
</script>
</BODY>
</HTML>

It falls in line with what you had sujested, but I was storeing the screen resolution into a Profile variable.

This idependent file was great because it gave me my screen resolution at the server level where I needed it. But I strated haveing problems with users still using IE6. Their system started doing an endless loop through this file.

I would call up this file through the folloing VBScript on my login page.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
If IsDBNull(Profile.ScreenResolution) Or Profile.ScreenResolution = "" Then
Response.Redirect("~/detectscreen.aspx")
Else
Dim uDispY As String = Right(Profile.ScreenResolution, (Len(Profile.ScreenResolution) - InStr(1, Profile.ScreenResolution, "x", CompareMethod.Text)))
Dim uDispX As String = Left(Profile.ScreenResolution, InStr(1, Profile.ScreenResolution, "x", CompareMethod.Text) - 1)
Profile.ScreenResolution = ""
End If
End If
End Sub

Now I found this code on a site and found it to work very well up until users started having problems. The best I can figure is that users need to flush their cookies and maybe their temp internet files. But I do not seam to have any problems with IE7.

If you can find a better way of doing this it could help out. My boss is currently wanting to find ways to control the browser to rectify the problems, which I keep saying is not posible.

Thanks
Mar 1 '07 #6
jhardman
3,406 Expert 2GB
If you can find a better way of doing this it could help out. My boss is currently wanting to find ways to control the browser to rectify the problems, which I keep saying is not posible.
No! You are doing everything just fine! I've noticed this problem before with ie6, it's just that by default when ie6 is told to reload a page it pulls it out of cache rather than reloading from the server. That's why you have the endless loop - it is pulling the first version you made of this page out of cache and reloading it without checking for an update. The problem should be temporary; by the time you have your permanent page done it should work. A good temporary fix (so you can still work on it until then) is to type another argument into the URL. If the URL is different, ie6 should try to reload it again. So you can just add a dummy variable like this:

http://www.mySite.com/default.asp?dummy=me

The ASP doesn't handle it so will ignore it, but ie6 will ask the server to make sure. A good permanent fix is to send the reload to a different page altogether. That's what you're doing now, right? But one of your first versions didn't?

Jared
Mar 2 '07 #7
Thanks, I am glad to know that I was not doing anything wrong then. If IE6 as you said, is loading from the cache as I felt it was, then your temperary patch should correct this for now.

I feel though that I will be running into this again some time down the road. Any other ideas on how to force IE6 to download a new copy and not work from cache?

Thanks
JRatcliff
Mar 5 '07 #8
jhardman
3,406 Expert 2GB
I usually get this problem on accident, I make a mistake and realize that now I can't access the page because it is just looping, or redirecting without checking. One solution is to not redirect until you have the page ready - maybe just open an alert as sort of a place holder. The only other thing I can think of is what I said above, add a dummy variable into the URL. Other than that, clear the browser cache?

The javascript forum might have more suggestions.

Jared
Mar 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: M P | last post by:
I can easily get the current date by using Date(), how about WorkWeek? Mark
7
by: Bredahl jensen | last post by:
Most of the the solution i have seen was throught javascript. Many thanks in advance JB
1
by: Winista | last post by:
I have a library that reads PDF file and manipilates its content. And I use SharpZip library to decompress the streams included in PDF file. All well and good. I have 3 lines of my test code that...
9
by: ShaneFowlkes | last post by:
Hey guys... I have a form that asks for several dates. I tried using asp calendar controls to set values of the date textboxes which were readonly. I found this annoying since each time I...
4
by: hvj | last post by:
I need to run a .NET1.1 program in a .NET2.0 CLR. The .NET1.1 exe starts correctly in .NET2.0. Now I want to debug in Visual Studio 2005. But when I try to open the .NET1.1 project, Visual Studio...
4
by: InnoCreate | last post by:
Hi everyone, I've developed a couple of asp.net1.1 websites and these are viewable using my mobile phone. I've now moved over to asp.net2 and i'm unable to view asp.net2 websites on my phone. I've...
2
by: LostnCode | last post by:
Hi, Can anyone help, I need to convert his code from vbscript to sharp C# for use with ASP.Net2.0? This is my first time using a forum. I don't know anything about either coding language so...
0
by: RazSam | last post by:
Hi Has anyone used the ComponentGo Web calendar control, If any one has please can they answer some question please. 1) How can display the time line such as the HoursDayBegin and HoursDayEnd?...
0
by: cwalden | last post by:
Hello, in my project i want to create a splash screen and after 5 seconds load the proper hta. But when i load it the splash is just white. I have to put my mouse over it to see the splash screen. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.