By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,916 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,916 IT Pros & Developers. It's quick & easy.

screen resolution

P: n/a
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?
Nov 19 '05 #1
Share this Question
Share on Google+
18 Replies


P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.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?

Nov 19 '05 #2

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.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?


Nov 19 '05 #3

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.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?


Nov 19 '05 #4

P: n/a
Change to:

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

and use resW.Value.

Eliyahu

"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.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?


Nov 19 '05 #5

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@micros oft.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?


Nov 19 '05 #6

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.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?


Nov 19 '05 #7

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@micros oft.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?

Nov 19 '05 #8

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
> > news:BC**********************************@microsof t.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?
> >
> >
> >


Nov 19 '05 #9

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:BC**********************************@microsof t.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?


Nov 19 '05 #10

P: n/a
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" <Da****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> news:BC**********************************@microsof t.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?
>>
>>
>>


Nov 19 '05 #11

P: n/a
<HEAD>
For the header description, i've used all sorts of variations as follow -
<script language="javascript">
//document.getElementById('resW') = window.screen.width;
//document.getElementById('resH') = window.screen.height;
alert(window.screen.width);
alert(window.screen.height);
//resW.value = window.screen.width;
//resH.value = window.screen.height;
document.Form1.resW.value = screen.width;
document.Form1.resH.value = screen.height;
</script>
</HEAD>
<BODY bottomMargin="5" background="images\horse_line.gif" topMargin="5"
MS_POSITIONING="GridLayout">
<FORM id="Form1" method="post" runat="server">
<input type=hidden name=resW id=resW runat=server>
<input type=hidden name=resH id=resH runat=server>
-----------------------------------------------------------------------------
I'm using a button control to post event, and then I attempt to review
variable information in code ---

_Width=resW.Value
_Width=Request.Form("resW")

Both return null strings.

I've added the following in page load for button control...
btn_V.Attributes.Add("onclick", "javascript:document:form1.submit()" )

Any help here? Please advise

"S. Justin Gengo" wrote:
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" <Da****@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
> > news:BC**********************************@microsof t.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?
> >
> >
> >


Nov 19 '05 #12

P: n/a
David,

Did you see my post above with a working example?

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:2B**********************************@microsof t.com...
<HEAD>
For the header description, i've used all sorts of variations as
follow -
<script language="javascript">
//document.getElementById('resW') = window.screen.width;
//document.getElementById('resH') = window.screen.height;
alert(window.screen.width);
alert(window.screen.height);
//resW.value = window.screen.width;
//resH.value = window.screen.height;
document.Form1.resW.value = screen.width;
document.Form1.resH.value = screen.height;
</script>
</HEAD>
<BODY bottomMargin="5" background="images\horse_line.gif" topMargin="5"
MS_POSITIONING="GridLayout">
<FORM id="Form1" method="post" runat="server">
<input type=hidden name=resW id=resW runat=server>
<input type=hidden name=resH id=resH runat=server>
-----------------------------------------------------------------------------
I'm using a button control to post event, and then I attempt to review
variable information in code ---

_Width=resW.Value
_Width=Request.Form("resW")

Both return null strings.

I've added the following in page load for button control...
btn_V.Attributes.Add("onclick", "javascript:document:form1.submit()" )

Any help here? Please advise

"S. Justin Gengo" wrote:
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" <Da****@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> > > news:BC**********************************@microsof t.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?
>> > >
>> > >
>> > >
>>
>>
>>


Nov 19 '05 #13

P: n/a
you need to do the postback. try:

<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>
<script>
document.getElementsByTag('resW')[0].value = window.screen.width;
document.getElementsByTag('resH')[0].value = window.screen.height;
</script

in the code behind in OnLoad

if (!IsPostBack)
{
RegisterStartupScript("<script>document.forms['Form1'].submit();</script>");
}
else
{
string resW = Request.Form["resW"];
string resH = Request.Form["resH"];
}
-- bruce (sqlwork.com)
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
> > news:BC**********************************@microsof t.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?
> >
> >
> >


Nov 19 '05 #14

P: n/a
I did use this code - and it does work, but there's one issue I'm seeing. In
the page load function, for the very first time, you call the javacode via
ScreenSize startup script. When no postbacks, the following is observed - i)
for first time (NO POSTBACKS), the values are present for
Request.Form("resW") and Request.Form("resH"). If I do a 2nd POSTBACK, then
the values are null. I have workaround using session variables - after 1st
post - but my questions are now as follows (for clarification - and for my
understanding)....
1) <input ... runat=server> runat=server not required since not posting on
events
2) why the 2nd postback, the Request.Form("resW"), Request.Form("resH")
doesn't work.
3) why does the source block I've submitted earlier not work too.

Thanks always,
David

"S. Justin Gengo" wrote:
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" <Da****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> news:BC**********************************@microsof t.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?
>>
>>
>>


Nov 19 '05 #15

P: n/a
David,

To answer your questions:

1) runat=server is only needed if you want to access a web control in the
code behind page. Since the hidden inputs are accessible via the Request
object there is no need for the overhead. Especially since you aren't really
using the inputs as dynamic controls.

2) It would work, if you run the javascript every time the page loads. Note
that I've placed the script inside of a If Not IsPostBack so the values for
the inputs are only being set the first time. The javascript setting them is
non-existent after the first page load. There is no need to keep running the
script because, as you've discovered on your own, it's more efficient to
just store the values in a session variable or viewstate since they won't
change.

3) Well, I can't be absolutely certain why your source block wasn't working.
It could be where you were inserting it on the page. It could be that it
didn't have the .value appended (but I assume you changed that based on
earlier posts). Or it could be that the way you were placing it on the page
it just wasn't getting fired. It's very difficult to say without seeing the
code for the entire page...

I hope these answers help. If you need any further clarification let me
know.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
I did use this code - and it does work, but there's one issue I'm seeing.
In
the page load function, for the very first time, you call the javacode via
ScreenSize startup script. When no postbacks, the following is observed -
i)
for first time (NO POSTBACKS), the values are present for
Request.Form("resW") and Request.Form("resH"). If I do a 2nd POSTBACK,
then
the values are null. I have workaround using session variables - after
1st
post - but my questions are now as follows (for clarification - and for my
understanding)....
1) <input ... runat=server> runat=server not required since not posting on
events
2) why the 2nd postback, the Request.Form("resW"), Request.Form("resH")
doesn't work.
3) why does the source block I've submitted earlier not work too.

Thanks always,
David

"S. Justin Gengo" wrote:
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" <Da****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> >> news:BC**********************************@microsof t.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?
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #16

P: n/a
Thank you again - you've resolved my problem - and answered my questions too.
Also, you've confirmed my understanding too in (1) and (2). As far as (3)
does - your's works - I'll review (when I have time), my section in more
detail with yours - as long as I know the "document.getElementById()"
function works (I was suspecting issue with it - since it was first time
used), but now that I have working version, I can experiment to find reason.

Again - you were awesome in getting answer to all my questions. Have great
day.

"S. Justin Gengo" wrote:
David,

To answer your questions:

1) runat=server is only needed if you want to access a web control in the
code behind page. Since the hidden inputs are accessible via the Request
object there is no need for the overhead. Especially since you aren't really
using the inputs as dynamic controls.

2) It would work, if you run the javascript every time the page loads. Note
that I've placed the script inside of a If Not IsPostBack so the values for
the inputs are only being set the first time. The javascript setting them is
non-existent after the first page load. There is no need to keep running the
script because, as you've discovered on your own, it's more efficient to
just store the values in a session variable or viewstate since they won't
change.

3) Well, I can't be absolutely certain why your source block wasn't working.
It could be where you were inserting it on the page. It could be that it
didn't have the .value appended (but I assume you changed that based on
earlier posts). Or it could be that the way you were placing it on the page
it just wasn't getting fired. It's very difficult to say without seeing the
code for the entire page...

I hope these answers help. If you need any further clarification let me
know.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
I did use this code - and it does work, but there's one issue I'm seeing.
In
the page load function, for the very first time, you call the javacode via
ScreenSize startup script. When no postbacks, the following is observed -
i)
for first time (NO POSTBACKS), the values are present for
Request.Form("resW") and Request.Form("resH"). If I do a 2nd POSTBACK,
then
the values are null. I have workaround using session variables - after
1st
post - but my questions are now as follows (for clarification - and for my
understanding)....
1) <input ... runat=server> runat=server not required since not posting on
events
2) why the 2nd postback, the Request.Form("resW"), Request.Form("resH")
doesn't work.
3) why does the source block I've submitted earlier not work too.

Thanks always,
David

"S. Justin Gengo" wrote:
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" <Da****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> >> news:BC**********************************@microsof t.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?
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #17

P: n/a
Thank you too. I had this answered above - but your response give me
variation and I'll review the best solution for my needs - or revise what I
have based on all inputs received.

Again, thanks to yourself and S. Justing Gengo - both very prompt and
professional solutions for me. Kind regards, always!

"Bruce Barker" wrote:
you need to do the postback. try:

<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>
<script>
document.getElementsByTag('resW')[0].value = window.screen.width;
document.getElementsByTag('resH')[0].value = window.screen.height;
</script

in the code behind in OnLoad

if (!IsPostBack)
{
RegisterStartupScript("<script>document.forms['Form1'].submit();</script>");
}
else
{
string resW = Request.Form["resW"];
string resH = Request.Form["resH"];
}
-- bruce (sqlwork.com)
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
> > news:BC**********************************@microsof t.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?
> >
> >
> >


Nov 19 '05 #18

P: n/a
David,

Glad I could help, Have good one!

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Thank you again - you've resolved my problem - and answered my questions
too.
Also, you've confirmed my understanding too in (1) and (2). As far as (3)
does - your's works - I'll review (when I have time), my section in more
detail with yours - as long as I know the "document.getElementById()"
function works (I was suspecting issue with it - since it was first time
used), but now that I have working version, I can experiment to find
reason.

Again - you were awesome in getting answer to all my questions. Have
great
day.

"S. Justin Gengo" wrote:
David,

To answer your questions:

1) runat=server is only needed if you want to access a web control in the
code behind page. Since the hidden inputs are accessible via the Request
object there is no need for the overhead. Especially since you aren't
really
using the inputs as dynamic controls.

2) It would work, if you run the javascript every time the page loads.
Note
that I've placed the script inside of a If Not IsPostBack so the values
for
the inputs are only being set the first time. The javascript setting them
is
non-existent after the first page load. There is no need to keep running
the
script because, as you've discovered on your own, it's more efficient to
just store the values in a session variable or viewstate since they won't
change.

3) Well, I can't be absolutely certain why your source block wasn't
working.
It could be where you were inserting it on the page. It could be that it
didn't have the .value appended (but I assume you changed that based on
earlier posts). Or it could be that the way you were placing it on the
page
it just wasn't getting fired. It's very difficult to say without seeing
the
code for the entire page...

I hope these answers help. If you need any further clarification let me
know.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"DavidS" <Da****@discussions.microsoft.com> wrote in message
news:D7**********************************@microsof t.com...
>I did use this code - and it does work, but there's one issue I'm
>seeing.
>In
> the page load function, for the very first time, you call the javacode
> via
> ScreenSize startup script. When no postbacks, the following is
> observed -
> i)
> for first time (NO POSTBACKS), the values are present for
> Request.Form("resW") and Request.Form("resH"). If I do a 2nd POSTBACK,
> then
> the values are null. I have workaround using session variables - after
> 1st
> post - but my questions are now as follows (for clarification - and for
> my
> understanding)....
> 1) <input ... runat=server> runat=server not required since not posting
> on
> events
> 2) why the 2nd postback, the Request.Form("resW"), Request.Form("resH")
> doesn't work.
> 3) why does the source block I've submitted earlier not work too.
>
> Thanks always,
> David
>
> "S. Justin Gengo" wrote:
>
>> 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" <Da****@discussions.microsoft.com> wrote in message
>> news:ED**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> >> news:9C**********************************@microsof t.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" <Da****@discussions.microsoft.com> wrote in message
>> >> >> news:BC**********************************@microsof t.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?
>> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>> >>
>>
>>
>>


Nov 19 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.