<input type=hidden runat=server id=inhResW>
Eliyahu
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:BC4BCD15-B6F8-4577...@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?
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
"Out of chaos comes order."
Nietzsche
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:9CFC58BF-275B-4AF0...@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?
document.getElementById('resW').value = window.screen.width;
document.getElementById('resH').value = window.screen.height;
and use resW.Value.
Eliyahu
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:9CFC58BF-275B-4AF0...@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:
>
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:
>
>
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
"Out of chaos comes order."
Nietzsche
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:CE5B2D19-6763-4A1A...@microsoft.com...
Please advise - I have 3 replies - and now seem confused by the solution
presented by all.
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
"Out of chaos comes order."
Nietzsche
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:EDC43FD7-CD1F-406F...@microsoft.com...
_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
Did you see my post above with a working example?
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
"Out of chaos comes order."
Nietzsche
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:2B421072-C233-4CDF...@microsoft.com...
<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" <Dav...@discussions.microsoft.com> wrote in message
news:CE5B2D19-6763-4A1A...@microsoft.com...
Thanks always,
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
"Out of chaos comes order."
Nietzsche
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:D73B115E-AE50-4BAC...@microsoft.com...
Again - you were awesome in getting answer to all my questions. Have great
day.
Again, thanks to yourself and S. Justing Gengo - both very prompt and
professional solutions for me. Kind regards, always!
Glad I could help, Have good one!
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer
"Out of chaos comes order."
Nietzsche
"DavidS" <Dav...@discussions.microsoft.com> wrote in message
news:6296655D-EFE2-423C...@microsoft.com...