Assign Javascript value to asp session variable

Discussion in 'ASP General' started by philin007@gmail.com, Oct 9, 2006.

  1. Guest

    Hi ,

    I have the following javascript codes:
    ******************************************
    <script language="JavaScript">
    <!--
    ....
    .....
    if (nextRow >5)
    {
    <%Session("txtTotal")=%> = nextRow;

    for (var i=1; i<NewTotalRow; i++) {
    <%

    'session("txtBeginDT" & i) =
    'session("txtEndDT" & i) = %>
    }

    }

    ....
    ....
    // -->
    </script>
    ******************************************
    Does any one know if we can assign a javascript value to a asp session
    variable?
    eg [<%Session("txtTotal")=%> = nextRow; ]
    is this correct ?

    regards
    philin
     
    , Oct 9, 2006
    #1
    1. Advertising

  2. Patrice Guest

    I assume this is a client side script. You won't have (at least directly)
    access to session variables stored on the server when running client side
    code.

    A usual way to transmit client side computed values to the server is to
    store them in hidden fields that will the be read server side on the next
    submit (you need a server round trip whatever method you wan't to use)...

    --
    Patrice

    <> a écrit dans le message de news:
    ...
    > Hi ,
    >
    > I have the following javascript codes:
    > ******************************************
    > <script language="JavaScript">
    > <!--
    > ...
    > ....
    > if (nextRow >5)
    > {
    > <%Session("txtTotal")=%> = nextRow;
    >
    > for (var i=1; i<NewTotalRow; i++) {
    > <%
    >
    > 'session("txtBeginDT" & i) =
    > 'session("txtEndDT" & i) = %>
    > }
    >
    > }
    >
    > ...
    > ...
    > // -->
    > </script>
    > ******************************************
    > Does any one know if we can assign a javascript value to a asp session
    > variable?
    > eg [<%Session("txtTotal")=%> = nextRow; ]
    > is this correct ?
    >
    > regards
    > philin
    >
     
    Patrice, Oct 9, 2006
    #2
    1. Advertising

  3. <> wrote in message
    news:...
    > Hi ,
    >
    > I have the following javascript codes:
    > ******************************************
    > <script language="JavaScript">
    > <!--
    > ...
    > ....
    > if (nextRow >5)
    > {
    > <%Session("txtTotal")=%> = nextRow;
    >
    > for (var i=1; i<NewTotalRow; i++) {
    > <%
    >
    > 'session("txtBeginDT" & i) =
    > 'session("txtEndDT" & i) = %>
    > }
    >
    > }
    >
    > ...
    > ...
    > // -->
    > </script>
    > ******************************************
    > Does any one know if we can assign a javascript value to a asp session
    > variable?
    > eg [<%Session("txtTotal")=%> = nextRow; ]
    > is this correct ?
    >


    No. Javascript in this case is running in the browser on the client. It
    has no access to the session object which is on the server. Your need to
    either include this value in a Form field that is submited to the server or
    use another means to send the value from the client to the server. Perhaps
    the best solution is to reconsider the design and remove this requirement
    all together.



    > regards
    > philin
    >
     
    Anthony Jones, Oct 9, 2006
    #3
  4. Guest

    thanks guys..

    i think i will have to use hidden fields..there are new methods like
    ajax but not so familiar with it..Hidden fields the problem is the
    value can be seen(right click view source) tats why I was thinkin of
    using the session variable...looks like no other solution :)

    Anthony Jones wrote:
    > <> wrote in message
    > news:...
    > > Hi ,
    > >
    > > I have the following javascript codes:
    > > ******************************************
    > > <script language="JavaScript">
    > > <!--
    > > ...
    > > ....
    > > if (nextRow >5)
    > > {
    > > <%Session("txtTotal")=%> = nextRow;
    > >
    > > for (var i=1; i<NewTotalRow; i++) {
    > > <%
    > >
    > > 'session("txtBeginDT" & i) =
    > > 'session("txtEndDT" & i) = %>
    > > }
    > >
    > > }
    > >
    > > ...
    > > ...
    > > // -->
    > > </script>
    > > ******************************************
    > > Does any one know if we can assign a javascript value to a asp session
    > > variable?
    > > eg [<%Session("txtTotal")=%> = nextRow; ]
    > > is this correct ?
    > >

    >
    > No. Javascript in this case is running in the browser on the client. It
    > has no access to the session object which is on the server. Your need to
    > either include this value in a Form field that is submited to the server or
    > use another means to send the value from the client to the server. Perhaps
    > the best solution is to reconsider the design and remove this requirement
    > all together.
    >
    >
    >
    > > regards
    > > philin
    > >
     
    , Oct 9, 2006
    #4
  5. <> wrote in message
    news:...
    > thanks guys..
    >
    > i think i will have to use hidden fields..there are new methods like
    > ajax but not so familiar with it..Hidden fields the problem is the
    > value can be seen(right click view source) tats why I was thinkin of
    > using the session variable...looks like no other solution :)


    Being able to see internal values on the client is not a real problem.
    There's nothing stopping the user debugging and single stepping your code.
    So if you really do have something that a user must never be able to see, a
    browser based solution is not for you.


    >
    > Anthony Jones wrote:
    > > <> wrote in message
    > > news:...
    > > > Hi ,
    > > >
    > > > I have the following javascript codes:
    > > > ******************************************
    > > > <script language="JavaScript">
    > > > <!--
    > > > ...
    > > > ....
    > > > if (nextRow >5)
    > > > {
    > > > <%Session("txtTotal")=%> = nextRow;
    > > >
    > > > for (var i=1; i<NewTotalRow; i++) {
    > > > <%
    > > >
    > > > 'session("txtBeginDT" & i) =
    > > > 'session("txtEndDT" & i) = %>
    > > > }
    > > >
    > > > }
    > > >
    > > > ...
    > > > ...
    > > > // -->
    > > > </script>
    > > > ******************************************
    > > > Does any one know if we can assign a javascript value to a asp session
    > > > variable?
    > > > eg [<%Session("txtTotal")=%> = nextRow; ]
    > > > is this correct ?
    > > >

    > >
    > > No. Javascript in this case is running in the browser on the client.

    It
    > > has no access to the session object which is on the server. Your need

    to
    > > either include this value in a Form field that is submited to the server

    or
    > > use another means to send the value from the client to the server.

    Perhaps
    > > the best solution is to reconsider the design and remove this

    requirement
    > > all together.
    > >
    > >
    > >
    > > > regards
    > > > philin
    > > >

    >
     
    Anthony Jones, Oct 9, 2006
    #5
    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. Jesper Pedersen

    Assign value from datagrid to a session variable

    Jesper Pedersen, Oct 23, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    6,086
    Scott Allen
    Oct 24, 2004
  2. Matt
    Replies:
    8
    Views:
    53,772
    saravanavsk
    Jan 25, 2010
  3. Ranjan
    Replies:
    1
    Views:
    2,790
    Eliyahu Goldin
    Apr 10, 2007
  4. Matt
    Replies:
    2
    Views:
    889
    Anthony Judd
    Sep 25, 2004
  5. Mirovk
    Replies:
    2
    Views:
    174
    Mirovk
    Aug 22, 2006
Loading...

Share This Page