473,246 Members | 1,703 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,246 software developers and data experts.

Javascript variables in ASP.NET (screen resolution)

Frens,

I am trying to get screen resolution of the client machine using
javascript and use those values in my project. I looked at some of the
examples given in this group, i tried to implement the same but
everytime i get nulls, i tested javascript by keeping alert statements
and everything looks good to me....
I am trying to figure it out what peice of info is missing in this
code.....
Here is my code

In PageLoad....
===========
If (Not IsPostBack) Then
RegisterStartupScript("MyScript", _
"<script language=javascript>" & _
"document.forms['Form1'].submit();</script>")
Else
Dim resW As String = Request.Form("resW")
Dim resH As String = Request.Form("resH")
End If

In ASPX page
==========
<HTML>
<HEAD>
<script language="javascript">
document.getElementsByName('resW').value = screen.width;
document.getElementsByName('resH').value = screen.height;
</script>

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT id="resW" type="hidden" name="resW" runat="server">
<INPUT id="resH" type="hidden" name="resH" runat="server">
</form>
</body>
</HTML>

I looked at some examples posted in this site...saying that they are
able to get those values
<http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/7e8a1109b11b83a3/19a7705d4458e6e6?lnk=st&q=getting+Javascript+value s+in+ASP.NET&rnum=11&hl=en#19a7705d4458e6e6>

Thanks in advance...

Thanks
Srini

Dec 27 '06 #1
11 3159
"srini" <si****************@gmail.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...
document.getElementsByName('resW').value = screen.width;
document.getElementsByName('resH').value = screen.height;
document.getElementById('resW').value = screen.width;
document.getElementById('resH').value = screen.height;
Dec 27 '06 #2
getElementsByName returns an array (as names can be dup'd), so you want:
<script language="javascript">
document.getElementsByName('resW')[0].value = screen.width;
document.getElementsByName('resH')[0].value = screen.height;
</script>

-- bruce (sqlwork.com)
srini wrote:
Frens,

I am trying to get screen resolution of the client machine using
javascript and use those values in my project. I looked at some of the
examples given in this group, i tried to implement the same but
everytime i get nulls, i tested javascript by keeping alert statements
and everything looks good to me....
I am trying to figure it out what peice of info is missing in this
code.....
Here is my code

In PageLoad....
===========
If (Not IsPostBack) Then
RegisterStartupScript("MyScript", _
"<script language=javascript>" & _
"document.forms['Form1'].submit();</script>")
Else
Dim resW As String = Request.Form("resW")
Dim resH As String = Request.Form("resH")
End If

In ASPX page
==========
<HTML>
<HEAD>
<script language="javascript">
document.getElementsByName('resW').value = screen.width;
document.getElementsByName('resH').value = screen.height;
</script>

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT id="resW" type="hidden" name="resW" runat="server">
<INPUT id="resH" type="hidden" name="resH" runat="server">
</form>
</body>
</HTML>

I looked at some examples posted in this site...saying that they are
able to get those values
<http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/7e8a1109b11b83a3/19a7705d4458e6e6?lnk=st&q=getting+Javascript+value s+in+ASP.NET&rnum=11&hl=en#19a7705d4458e6e6>

Thanks in advance...

Thanks
Srini
Dec 27 '06 #3
Hi Mark,

This change wahtever u suggested does not seems to work...if we have
the "name" and "id" for any form hidden element, Only the "name" will
be taken care...in our case id will not work.

You can copy the code which i mentioned in the previous mail..and try
it..is there any workaround for this problem

Thanks
Srini
Mark Rae wrote:
"srini" <si****************@gmail.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...
document.getElementsByName('resW').value = screen.width;
document.getElementsByName('resH').value = screen.height;

document.getElementById('resW').value = screen.width;
document.getElementById('resH').value = screen.height;
Dec 27 '06 #4
Hi Bruce,

This does not seems to work. I already tried this way..is there
anyother possible workaround...

Thanks
Srini
bruce barker wrote:
getElementsByName returns an array (as names can be dup'd), so you want:
<script language="javascript">
document.getElementsByName('resW')[0].value = screen.width;
document.getElementsByName('resH')[0].value = screen.height;
</script>

-- bruce (sqlwork.com)
srini wrote:
Frens,

I am trying to get screen resolution of the client machine using
javascript and use those values in my project. I looked at some of the
examples given in this group, i tried to implement the same but
everytime i get nulls, i tested javascript by keeping alert statements
and everything looks good to me....
I am trying to figure it out what peice of info is missing in this
code.....
Here is my code

In PageLoad....
===========
If (Not IsPostBack) Then
RegisterStartupScript("MyScript", _
"<script language=javascript>" & _
"document.forms['Form1'].submit();</script>")
Else
Dim resW As String = Request.Form("resW")
Dim resH As String = Request.Form("resH")
End If

In ASPX page
==========
<HTML>
<HEAD>
<script language="javascript">
document.getElementsByName('resW').value = screen.width;
document.getElementsByName('resH').value = screen.height;
</script>

</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT id="resW" type="hidden" name="resW" runat="server">
<INPUT id="resH" type="hidden" name="resH" runat="server">
</form>
</body>
</HTML>

I looked at some examples posted in this site...saying that they are
able to get those values
<http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/7e8a1109b11b83a3/19a7705d4458e6e6?lnk=st&q=getting+Javascript+value s+in+ASP.NET&rnum=11&hl=en#19a7705d4458e6e6>

Thanks in advance...

Thanks
Srini
Dec 27 '06 #5
"srini" <si****************@gmail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
This change wahtever u suggested does not seems to work...if we have
the "name" and "id" for any form hidden element, Only the "name" will
be taken care...in our case id will not work.
That makes no sense at all...
You can copy the code which i mentioned in the previous mail..and try
it..
Works perfectly for me...
is there any workaround for this problem
I have no idea...
Dec 27 '06 #6
Hi Mark,

I tried with the change you suggested..but what iam getting is

document.getElementById('resW').value = screen.width;
document.getElementById('resH').value = screen.height;

Javascript error .......is not null or not an object..

Let me keep my code once again so that you can know what exactly iam
doing ..I am using ASP 1.1

In PageLoad
=========
Protected WithEvents resW As
System.Web.UI.HtmlControls.HtmlInputHidden
Protected WithEvents resH As
System.Web.UI.HtmlControls.HtmlInputHidden

If (Not IsPostBack) Then
RegisterStartupScript("MyScript", _
"<script language=javascript>" & _
"document.forms['Form1'].submit();</script>")
Else
Dim resW As String = Request.Form("resW")
Dim resH As String = Request.Form("resH")
End If

ASPX Page
=========
<HTML>
<HEAD>
<title>first</title>
<script language="javascript">
document.getElementByName('resW').value = screen.width
document.getElementByName('resH').value = screen.height
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<INPUT id="resW" type="hidden" name="resW" runat="server">
<INPUT id="resH" type="hidden" name="resH" runat="server">
</form>
</body>
</HTML>

What the values i get from resW and resH is nulls....

Thanks
Srini

On Dec 27, 10:23 am, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"srini" <sirumalla.srini...@gmail.comwrote in messagenews:11**********************@h40g2000cwb.g ooglegroups.com...
This change wahtever u suggested does not seems to work...if we have
the "name" and "id" for any form hidden element, Only the "name" will
be taken care...in our case id will not work.That makes no sense at all...
You can copy the code which i mentioned in the previous mail..and try
it..Works perfectly for me...
is there any workaround for this problemI have no idea...
Dec 27 '06 #7
"srini" <si****************@gmail.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
I tried with the change you suggested..but what iam getting is

document.getElementById('resW').value = screen.width;
document.getElementById('resH').value = screen.height;

Javascript error .......is not null or not an object..
OK - which *specific* line of the JavaScript causes the error...?
<script language="javascript">
Firstly, that is not XHTML-compliant - instead, you should be using

<script type="text/javascript">

However, I doubt very much that that is causing your problem.
document.getElementByName('resW').value = screen.width
document.getElementByName('resH').value = screen.height
Secondly, as has already been pointed out to you, that is *never* going to
work! The document object does *not* have a method called
"getElementByName" - I don't know how you imagine that it does... It has
methods called "getElementById" and "getElementsByName" - notice the "s" in
getElement*s*ByName.

http://www.google.co.uk/search?sourc...getElementById
http://www.google.co.uk/search?sourc...tElementByName
http://www.google.co.uk/search?hl=en...tsByName&meta=

Also, what browser are you using to test your code? "screen.width" and
"screen.height" will not work in all browsers
http://chattyfig.figleaf.com/piperma...ay/000103.html
Dec 27 '06 #8
Hi Mark,

Thanks for your reply...

#1 OK - which *specific* line of the JavaScript causes the error...?
document.getElementById('resW').value = screen.width;

Javascript error.. document.getElementById(' ') is not null or not an
object..

#2. document.getElementByName('resW').value = screen.width
This is typo....actually i declared in the program correctly

#3. Also, what browser are you using to test your code? "screen.width"
Iam using IE6.0

am i missing something ???..this is driving me crazy....

Thanks
Srini

Mark Rae wrote:
"srini" <si****************@gmail.comwrote in message
news:11*********************@f1g2000cwa.googlegrou ps.com...
I tried with the change you suggested..but what iam getting is

document.getElementById('resW').value = screen.width;
document.getElementById('resH').value = screen.height;

Javascript error .......is not null or not an object..

OK - which *specific* line of the JavaScript causes the error...?
<script language="javascript">

Firstly, that is not XHTML-compliant - instead, you should be using

<script type="text/javascript">

However, I doubt very much that that is causing your problem.
document.getElementByName('resW').value = screen.width
document.getElementByName('resH').value = screen.height

Secondly, as has already been pointed out to you, that is *never* going to
work! The document object does *not* have a method called
"getElementByName" - I don't know how you imagine that it does... It has
methods called "getElementById" and "getElementsByName" - notice the "s" in
getElement*s*ByName.

http://www.google.co.uk/search?sourc...getElementById
http://www.google.co.uk/search?sourc...tElementByName
http://www.google.co.uk/search?hl=en...tsByName&meta=

Also, what browser are you using to test your code? "screen.width" and
"screen.height" will not work in all browsers
http://chattyfig.figleaf.com/piperma...ay/000103.html
Dec 28 '06 #9
"srini" <si****************@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
#1 OK - which *specific* line of the JavaScript causes the error...?
document.getElementById('resW').value = screen.width;

Javascript error.. document.getElementById(' ') is not null or not an
object..
Er, well there's your problem right there!

document.getElementById(' ')

Unless this is another typo, the JavaScript is looking for a control whose
id is a space character, not resW or resH.

Do a View Source on the page...
Dec 28 '06 #10
Hi Mark,

Thanks for your reply...I got the result but this time i did it in
different way.

In Page Load event
==============
Dim popupScript As String = "<script
language=javascript>document.forms(0).action='seco nd.aspx?sWdHt=' +
screen.width + ',' + screen.height
;document.forms(0).submit();</script>"

If (Not IsPostBack) Then
RegisterStartupScript("MyScript", popupScript)
Else
Dim test as string = Request("sWdHt")
End If

NO ASPX changes

Now i could see the value in the string "test" . Appreciate your help
and it helped me lot in exploring new things.

Thanks
Srini

On Dec 27, 4:38 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"srini" <sirumalla.srini...@gmail.comwrote in messagenews:11**********************@73g2000cwn.go oglegroups.com...
#1 OK - which *specific* line of the JavaScript causes the error...?
document.getElementById('resW').value =screen.width;
Javascript error.. document.getElementById(' ') is not null or not an
object..Er, well there's your problem right there!

document.getElementById(' ')

Unless this is another typo, the JavaScript is looking for a control whose
id is a space character, not resW or resH.

Do a View Source on the page...
Dec 28 '06 #11
"srini" <si****************@gmail.comwrote in message
news:11**********************@i12g2000cwa.googlegr oups.com...

That's great.

You should still read up on XHTML-compliance, though, as your JavaScript is
quite non-compliant and *extremely* IE-specific...

<script language=javascript>
document.forms(0)

etc
Dec 28 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jay | last post by:
Hi everybody !! I am just wondering if Javascript and PHP can interact with each other ? Let's say i have a variable in Javascript ( call it "var x = 6;") Is there anyway that we can use "x"...
2
by: Ang Talunin | last post by:
Hey, How to do something like this: <head> <style> img { width: <script>blaat();</script>;} </style> <script> function blaat()
8
by: Victor | last post by:
I need a JavaScript timer - I have five events I need to time, that can be triggered by a mouseclick event, or a keypress event. Each event is separated by only one to two seconds. The first...
3
by: mbasil7 | last post by:
Hi at all! I want to use a javascript variable in php. The reason is that i want to know the client's screen resolution. Keep in mind that i am not a javascript programmer but php. Here is...
14
by: Seige | last post by:
Ever had headache when you can't resize the background width using CSS: body{ background: url(/images/bg.jpg) ; background-width: 800px; } It won't work, would it? Of course not, it's not even...
7
by: Norman Swartz | last post by:
I want to place some graphic images on the web that are optimally viewed at a resolution of 1024 by 768 pixels. Is it possible, within Javascript,to force a particular screen resolution?
19
by: mantrid | last post by:
I have the following link to bring up an alert with a figure in it based on the screen resolution. but instead of displaying a number 'NaN' is displayed. <a href="javascript:alert('Your ideal...
0
by: sirumalla.srinivas | last post by:
Frens, I am trying to get screen resolution of the client machine using javascript and use those values in my project. I looked at some of the examples given .net groups, i tried to implement...
7
crystal2005
by: crystal2005 | last post by:
Hi all, I'm currenty creating a website. I got one confusing problem related to CSS and JavaScript actually, not really html. The problem is, I actually want my welcome screen page is to be random...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.