472,353 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 5052
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...
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...
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...
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...
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...
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...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.