screen resolution

Discussion in 'ASP .Net' started by =?Utf-8?B?RGF2aWRT?=, Sep 7, 2005.

  1. 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?=, Sep 7, 2005
    #1
    1. Advertising

  2. 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" <> wrote in message
    > news:...
    > > 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?=, Sep 7, 2005
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    >> news:...
    >> > 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, Sep 7, 2005
    #3
  4. =?Utf-8?B?RGF2aWRT?=

    Franck Guest

    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" <> wrote in message
    >>news:...
    >>
    >>>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, Sep 7, 2005
    #4
  5. 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" <> wrote in message
    news:...
    > 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, Sep 7, 2005
    #5
  6. 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > > news:...
    > > > > 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?=, Sep 7, 2005
    #6
  7. 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" <> wrote in message
    > >>news:...
    > >>
    > >>>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?=, Sep 7, 2005
    #7
  8. 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" <> wrote in message
    news:...
    >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" <> wrote in message
    >> news:...
    >> > 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" <> wrote in message
    >> > > news:...
    >> > > > 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, Sep 7, 2005
    #8
  9. 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > >> news:...
    > >> > 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?=, Sep 7, 2005
    #9
  10. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    >> news:...
    >> > 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" <> wrote in message
    >> >> news:...
    >> >> > 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, Sep 7, 2005
    #10
  11. Change to:

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

    and use resW.Value.

    Eliyahu

    "DavidS" <> wrote in message
    news:...
    > 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" <> wrote in message
    > > news:...
    > > > 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, Sep 7, 2005
    #11
  12. <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" <> wrote in message
    > news:...
    > >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" <> wrote in message
    > >> news:...
    > >> > 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" <> wrote in message
    > >> > > news:...
    > >> > > > 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?=, Sep 7, 2005
    #12
  13. 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" <> wrote in message
    news:...
    > <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" <> wrote in message
    >> news:...
    >> >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" <> wrote in message
    >> >> news:...
    >> >> > 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" <> wrote in message
    >> >> > > news:...
    >> >> > > > 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, Sep 7, 2005
    #13
  14. =?Utf-8?B?RGF2aWRT?=

    Bruce Barker Guest

    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" <> wrote in message
    news:...
    >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" <> wrote in message
    >> news:...
    >> > 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" <> wrote in message
    >> > > news:...
    >> > > > 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?
    >> > >
    >> > >
    >> > >

    >>
    >>
    >>
     
    Bruce Barker, Sep 7, 2005
    #14
  15. 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > >> news:...
    > >> > 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" <> wrote in message
    > >> >> news:...
    > >> >> > 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?=, Sep 7, 2005
    #15
  16. 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" <> wrote in message
    news:D...
    >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" <> wrote in message
    >> news:...
    >> > 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" <> wrote in message
    >> >> news:...
    >> >> > 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" <> wrote in message
    >> >> >> news:...
    >> >> >> > 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, Sep 7, 2005
    #16
  17. 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" <> wrote in message
    > news:D...
    > >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" <> wrote in message
    > >> news:...
    > >> > 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" <> wrote in message
    > >> >> news:...
    > >> >> > 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" <> wrote in message
    > >> >> >> news:...
    > >> >> >> > 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?=, Sep 7, 2005
    #17
  18. 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" <> wrote in message
    > news:...
    > >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" <> wrote in message
    > >> news:...
    > >> > 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" <> wrote in message
    > >> > > news:...
    > >> > > > 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?=, Sep 7, 2005
    #18
  19. 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" <> wrote in message
    news:...
    > 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" <> wrote in message
    >> news:D...
    >> >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" <> wrote in message
    >> >> news:...
    >> >> > 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" <> wrote in message
    >> >> >> news:...
    >> >> >> > 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" <> wrote in message
    >> >> >> >> news:...
    >> >> >> >> > 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, Sep 7, 2005
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew FPGA
    Replies:
    0
    Views:
    976
    Andrew FPGA
    Sep 26, 2005
  2. Jenny

    Screen resolution

    Jenny, Aug 26, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    369
    Ken Schaefer
    Aug 26, 2003
  3. Screen resolution

    , Nov 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    344
    Teemu Keiski
    Nov 3, 2003
  4. Guadala Harry

    Discover User's Screen Resolution

    Guadala Harry, Jul 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    413
    bruce barker
    Jul 1, 2004
  5. Pat
    Replies:
    5
    Views:
    543
Loading...

Share This Page