Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   screen resolution (http://www.velocityreviews.com/forums/t109390-screen-resolution.html)

=?Utf-8?B?RGF2aWRT?= 09-07-2005 02:22 PM

screen resolution
 
Have resW=screen.width; resH=screen.height in javascript. How can I read
these values in ASP.NET source code - Page_Load function of code behind?

Any suggestions?

=?Utf-8?B?RGF2aWRT?= 09-07-2005 02:55 PM

Re: screen resolution
 
I've have the following in HTML code...
<script language="javascript">
document.getElementById('resW') = window.screen.width;
document.getElementById('resH') = window.screen.height;
</script>
<input type=hidden name=resW id=resW runat=server>
<input type=hidden name=resH id=resH runat=server>

How can I access the values in ASP.NET (VB) code behind? I keep getting
null values when I use Request.Form("resW") or resW.Value?

What am I missing?

"Eliyahu Goldin" wrote:

> You need to pass the values from client to server side. The standard way is
> to use hidden input controls:
>
> <input type=hidden runat=server id=inhResW>
>
> Eliyahu
>
> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
> news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
> > Have resW=screen.width; resH=screen.height in javascript. How can I read
> > these values in ASP.NET source code - Page_Load function of code behind?
> >
> > Any suggestions?

>
>
>


S. Justin Gengo 09-07-2005 03:03 PM

Re: screen resolution
 
David,

I can think of two things that may be happening.

The first is that there won't be any value in either of those fields until a
postback has occurred. The first time your code runs the page hasn't
displayed on the client and the javascript hasn't filled those fields.

The second (if the problem isn't the first) is that setting the controls as
runat="Server" may be interfering with the process. If you're going to use
Request.Form to get the values the controls don't have to be .Net controls.
You would only use runat="Server" if you want to reference the hidden inputs
as .Net server side controls. To do that you should declare them on your
page something like:

Protected WithEvents resW As System.Web.HtmlControls.HtmlGenericControl

(I typed that from memory, so double check the system declaration...)

But from the looks of things I would just remove the runat="Server" and then
do the Request.Form on postback only.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <DavidS@discussions.microsoft.com> wrote in message
news:9CFC58BF-275B-4AF0-8306-420C6346376B@microsoft.com...
> I've have the following in HTML code...
> <script language="javascript">
> document.getElementById('resW') = window.screen.width;
> document.getElementById('resH') = window.screen.height;
> </script>
> <input type=hidden name=resW id=resW runat=server>
> <input type=hidden name=resH id=resH runat=server>
>
> How can I access the values in ASP.NET (VB) code behind? I keep getting
> null values when I use Request.Form("resW") or resW.Value?
>
> What am I missing?
>
> "Eliyahu Goldin" wrote:
>
>> You need to pass the values from client to server side. The standard way
>> is
>> to use hidden input controls:
>>
>> <input type=hidden runat=server id=inhResW>
>>
>> Eliyahu
>>
>> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
>> news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
>> > Have resW=screen.width; resH=screen.height in javascript. How can I
>> > read
>> > these values in ASP.NET source code - Page_Load function of code
>> > behind?
>> >
>> > Any suggestions?

>>
>>
>>




Franck 09-07-2005 03:09 PM

Re: screen resolution
 
DavidS wrote:
> I've have the following in HTML code...
> <script language="javascript">
> document.getElementById('resW') = window.screen.width;
> document.getElementById('resH') = window.screen.height;


have you tried
document.getElementById('resW').value = window.screen.width;
document.getElementById('resH').value = window.screen.height;
instead?
> </script>
> <input type=hidden name=resW id=resW runat=server>
> <input type=hidden name=resH id=resH runat=server>
>
> How can I access the values in ASP.NET (VB) code behind? I keep getting
> null values when I use Request.Form("resW") or resW.Value?
>
> What am I missing?
>
> "Eliyahu Goldin" wrote:
>
>
>>You need to pass the values from client to server side. The standard way is
>>to use hidden input controls:
>>
>><input type=hidden runat=server id=inhResW>
>>
>>Eliyahu
>>
>>"DavidS" <DavidS@discussions.microsoft.com> wrote in message
>>news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
>>
>>>Have resW=screen.width; resH=screen.height in javascript. How can I read
>>>these values in ASP.NET source code - Page_Load function of code behind?
>>>
>>>Any suggestions?

>>
>>
>>


Eliyahu Goldin 09-07-2005 03:32 PM

Re: screen resolution
 
You need to pass the values from client to server side. The standard way is
to use hidden input controls:

<input type=hidden runat=server id=inhResW>

Eliyahu

"DavidS" <DavidS@discussions.microsoft.com> wrote in message
news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
> Have resW=screen.width; resH=screen.height in javascript. How can I read
> these values in ASP.NET source code - Page_Load function of code behind?
>
> Any suggestions?




=?Utf-8?B?RGF2aWRT?= 09-07-2005 03:40 PM

Re: screen resolution
 
I still get nothing for resW.value!

"Eliyahu Goldin" wrote:

> Change to:
>
> document.getElementById('resW').value = window.screen.width;
> document.getElementById('resH').value = window.screen.height;
>
> and use resW.Value.
>
> Eliyahu
>
> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
> news:9CFC58BF-275B-4AF0-8306-420C6346376B@microsoft.com...
> > I've have the following in HTML code...
> > <script language="javascript">
> > document.getElementById('resW') = window.screen.width;
> > document.getElementById('resH') = window.screen.height;
> > </script>
> > <input type=hidden name=resW id=resW runat=server>
> > <input type=hidden name=resH id=resH runat=server>
> >
> > How can I access the values in ASP.NET (VB) code behind? I keep getting
> > null values when I use Request.Form("resW") or resW.Value?
> >
> > What am I missing?
> >
> > "Eliyahu Goldin" wrote:
> >
> > > You need to pass the values from client to server side. The standard way

> is
> > > to use hidden input controls:
> > >
> > > <input type=hidden runat=server id=inhResW>
> > >
> > > Eliyahu
> > >
> > > "DavidS" <DavidS@discussions.microsoft.com> wrote in message
> > > news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
> > > > Have resW=screen.width; resH=screen.height in javascript. How can I

> read
> > > > these values in ASP.NET source code - Page_Load function of code

> behind?
> > > >
> > > > Any suggestions?
> > >
> > >
> > >

>
>
>


=?Utf-8?B?RGF2aWRT?= 09-07-2005 03:40 PM

Re: screen resolution
 
Yes - but getting nothing (vbNullstring) for values in ASP.NET

"Franck" wrote:

> DavidS wrote:
> > I've have the following in HTML code...
> > <script language="javascript">
> > document.getElementById('resW') = window.screen.width;
> > document.getElementById('resH') = window.screen.height;

>
> have you tried
> document.getElementById('resW').value = window.screen.width;
> document.getElementById('resH').value = window.screen.height;
> instead?
> > </script>
> > <input type=hidden name=resW id=resW runat=server>
> > <input type=hidden name=resH id=resH runat=server>
> >
> > How can I access the values in ASP.NET (VB) code behind? I keep getting
> > null values when I use Request.Form("resW") or resW.Value?
> >
> > What am I missing?
> >
> > "Eliyahu Goldin" wrote:
> >
> >
> >>You need to pass the values from client to server side. The standard way is
> >>to use hidden input controls:
> >>
> >><input type=hidden runat=server id=inhResW>
> >>
> >>Eliyahu
> >>
> >>"DavidS" <DavidS@discussions.microsoft.com> wrote in message
> >>news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
> >>
> >>>Have resW=screen.width; resH=screen.height in javascript. How can I read
> >>>these values in ASP.NET source code - Page_Load function of code behind?
> >>>
> >>>Any suggestions?
> >>
> >>
> >>

>


S. Justin Gengo 09-07-2005 03:46 PM

Re: screen resolution
 
David,

After you bring up your page on the client do a view source and check the
hidden inputs and see if the value exists there or not.

If it doesn't, show us how you're calling the initial javascript on page
load.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <DavidS@discussions.microsoft.com> wrote in message
news:CE5B2D19-6763-4A1A-910F-76DB584B85FD@microsoft.com...
>I still get nothing for resW.value!
>
> "Eliyahu Goldin" wrote:
>
>> Change to:
>>
>> document.getElementById('resW').value = window.screen.width;
>> document.getElementById('resH').value = window.screen.height;
>>
>> and use resW.Value.
>>
>> Eliyahu
>>
>> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
>> news:9CFC58BF-275B-4AF0-8306-420C6346376B@microsoft.com...
>> > I've have the following in HTML code...
>> > <script language="javascript">
>> > document.getElementById('resW') = window.screen.width;
>> > document.getElementById('resH') = window.screen.height;
>> > </script>
>> > <input type=hidden name=resW id=resW runat=server>
>> > <input type=hidden name=resH id=resH runat=server>
>> >
>> > How can I access the values in ASP.NET (VB) code behind? I keep
>> > getting
>> > null values when I use Request.Form("resW") or resW.Value?
>> >
>> > What am I missing?
>> >
>> > "Eliyahu Goldin" wrote:
>> >
>> > > You need to pass the values from client to server side. The standard
>> > > way

>> is
>> > > to use hidden input controls:
>> > >
>> > > <input type=hidden runat=server id=inhResW>
>> > >
>> > > Eliyahu
>> > >
>> > > "DavidS" <DavidS@discussions.microsoft.com> wrote in message
>> > > news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
>> > > > Have resW=screen.width; resH=screen.height in javascript. How can
>> > > > I

>> read
>> > > > these values in ASP.NET source code - Page_Load function of code

>> behind?
>> > > >
>> > > > Any suggestions?
>> > >
>> > >
>> > >

>>
>>
>>




=?Utf-8?B?RGF2aWRT?= 09-07-2005 03:47 PM

Re: screen resolution
 
Any example code I can review to get this to work is appreciated. I'd think
this wouldn't be complicated - but right now, I'm getting null values from
solutions recommended. Again, I simply want to read the screen resolution on
the client. In the ASP.NET code - after a postback, I simply then want to be
able to read these javascript values and do respective processing.

Please advise - I have 3 replies - and now seem confused by the solution
presented by all.


"S. Justin Gengo" wrote:

> David,
>
> I can think of two things that may be happening.
>
> The first is that there won't be any value in either of those fields until a
> postback has occurred. The first time your code runs the page hasn't
> displayed on the client and the javascript hasn't filled those fields.
>
> The second (if the problem isn't the first) is that setting the controls as
> runat="Server" may be interfering with the process. If you're going to use
> Request.Form to get the values the controls don't have to be .Net controls.
> You would only use runat="Server" if you want to reference the hidden inputs
> as .Net server side controls. To do that you should declare them on your
> page something like:
>
> Protected WithEvents resW As System.Web.HtmlControls.HtmlGenericControl
>
> (I typed that from memory, so double check the system declaration...)
>
> But from the looks of things I would just remove the runat="Server" and then
> do the Request.Form on postback only.
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
> news:9CFC58BF-275B-4AF0-8306-420C6346376B@microsoft.com...
> > I've have the following in HTML code...
> > <script language="javascript">
> > document.getElementById('resW') = window.screen.width;
> > document.getElementById('resH') = window.screen.height;
> > </script>
> > <input type=hidden name=resW id=resW runat=server>
> > <input type=hidden name=resH id=resH runat=server>
> >
> > How can I access the values in ASP.NET (VB) code behind? I keep getting
> > null values when I use Request.Form("resW") or resW.Value?
> >
> > What am I missing?
> >
> > "Eliyahu Goldin" wrote:
> >
> >> You need to pass the values from client to server side. The standard way
> >> is
> >> to use hidden input controls:
> >>
> >> <input type=hidden runat=server id=inhResW>
> >>
> >> Eliyahu
> >>
> >> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
> >> news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
> >> > Have resW=screen.width; resH=screen.height in javascript. How can I
> >> > read
> >> > these values in ASP.NET source code - Page_Load function of code
> >> > behind?
> >> >
> >> > Any suggestions?
> >>
> >>
> >>

>
>
>


S. Justin Gengo 09-07-2005 04:06 PM

Re: screen resolution
 
David,

Here's working code:

Form:

<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Post Back"></asp:Button>
<INPUT id="resW" type="hidden" name="resW">
<INPUT id="resH" type="hidden" name="resH">
</form>



Code Behind:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Try
'---Every page load

If Not IsPostBack Then
'---First page load only
Dim StringBuilder As New System.Text.StringBuilder
With StringBuilder
.Append("<script language=""javascript"">" & vbCrLf)
.Append("document.getElementById('resW').value =
window.screen.width;" & vbCrLf)
.Append("document.getElementById('resH').value =
window.screen.height;" & vbCrLf)
.Append("</script>" & vbCrLf)
End With

Page.RegisterStartupScript("ScreenSize",
StringBuilder.ToString)
Else
'---Post back only
Dim Width As Int32 = CType(Request.Form("resW"), Int32)
Dim Height As Int32 = CType(Request.Form("resH"), Int32)

Response.Write(Width.ToString & " X " & Height.ToString)
End If
'---Every page load
Catch ex As Exception
'---Handle exceptions here.
End Try
End Sub


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <DavidS@discussions.microsoft.com> wrote in message
news:EDC43FD7-CD1F-406F-9D3F-4E47D8B77DAF@microsoft.com...
> Any example code I can review to get this to work is appreciated. I'd
> think
> this wouldn't be complicated - but right now, I'm getting null values from
> solutions recommended. Again, I simply want to read the screen resolution
> on
> the client. In the ASP.NET code - after a postback, I simply then want to
> be
> able to read these javascript values and do respective processing.
>
> Please advise - I have 3 replies - and now seem confused by the solution
> presented by all.
>
>
> "S. Justin Gengo" wrote:
>
>> David,
>>
>> I can think of two things that may be happening.
>>
>> The first is that there won't be any value in either of those fields
>> until a
>> postback has occurred. The first time your code runs the page hasn't
>> displayed on the client and the javascript hasn't filled those fields.
>>
>> The second (if the problem isn't the first) is that setting the controls
>> as
>> runat="Server" may be interfering with the process. If you're going to
>> use
>> Request.Form to get the values the controls don't have to be .Net
>> controls.
>> You would only use runat="Server" if you want to reference the hidden
>> inputs
>> as .Net server side controls. To do that you should declare them on your
>> page something like:
>>
>> Protected WithEvents resW As System.Web.HtmlControls.HtmlGenericControl
>>
>> (I typed that from memory, so double check the system declaration...)
>>
>> But from the looks of things I would just remove the runat="Server" and
>> then
>> do the Request.Form on postback only.
>>
>> --
>> Sincerely,
>>
>> S. Justin Gengo, MCP
>> Web Developer / Programmer
>>
>> www.aboutfortunate.com
>>
>> "Out of chaos comes order."
>> Nietzsche
>> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
>> news:9CFC58BF-275B-4AF0-8306-420C6346376B@microsoft.com...
>> > I've have the following in HTML code...
>> > <script language="javascript">
>> > document.getElementById('resW') = window.screen.width;
>> > document.getElementById('resH') = window.screen.height;
>> > </script>
>> > <input type=hidden name=resW id=resW runat=server>
>> > <input type=hidden name=resH id=resH runat=server>
>> >
>> > How can I access the values in ASP.NET (VB) code behind? I keep
>> > getting
>> > null values when I use Request.Form("resW") or resW.Value?
>> >
>> > What am I missing?
>> >
>> > "Eliyahu Goldin" wrote:
>> >
>> >> You need to pass the values from client to server side. The standard
>> >> way
>> >> is
>> >> to use hidden input controls:
>> >>
>> >> <input type=hidden runat=server id=inhResW>
>> >>
>> >> Eliyahu
>> >>
>> >> "DavidS" <DavidS@discussions.microsoft.com> wrote in message
>> >> news:BC4BCD15-B6F8-4577-A44B-2F6F7DB38746@microsoft.com...
>> >> > Have resW=screen.width; resH=screen.height in javascript. How can I
>> >> > read
>> >> > these values in ASP.NET source code - Page_Load function of code
>> >> > behind?
>> >> >
>> >> > Any suggestions?
>> >>
>> >>
>> >>

>>
>>
>>





All times are GMT. The time now is 01:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.