Is refreshing a page in JavaScript the same as posting it back?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Is refreshing a page in JavaScript the same as posting it back?

  1. #1
    Jason Salas Guest

    Is refreshing a page in JavaScript the same as posting it back?

    Hi everyone,

    I've got an interesting problem...is refreshing a page through client-side
    JavaScript, specifically:

    <script language="JavaScript">
    // refreshes the current page every 9 seconds
    var intervalID;
    intervalID = window.setInterval("nextSlide()",9000);
    function nextSlide()
    {
    document.execCommand("Refresh");
    }
    </script>

    ....the same functionally as posting a page back? And if so, is ViewState
    not programmatically controllable? I'm thinking perhaps not, because I'm
    trying to develop a slide show control that first populates an array, and
    then stores a single integer value in ViewState and then increment that
    value so that one element within the array is shown at a time:

    //1st page load:
    int currentSlide = (int)ViewState["nextSlide"];
    arrSlide[0] = // display contents;
    ViewState["nextSlide"] = currentSlide + 1;

    //2nd page load:
    int currentSlide = (int)ViewState["nextSlide"];
    arrSlide[1] = // display contents;
    ViewState["nextSlide"] = currentSlide + 1;

    //nth page load:
    int currentSlide = (int)ViewState["nextSlide"];
    arrSlide[n] = // display contents;
    ViewState["nextSlide"] = currentSlide + 1;

    The JavaScript above is written to the client page so that that page reloads
    automatically, and in theory displays the next slide in the series. But for
    some reason, when I refresh the page with the JavaScript, I'm always getting
    the first value of ViewState (being 0), so I never advance past the first
    slide. This leads me to believe that refreshing the page isn't actually
    posting back and not persisting data in ViewState. Got any ideas?

    I was thinking that if this is the case (not actually posting back), then
    I'll roll a custom event and use the postback interfaces for controls.

    Thanks!

    Jas



  2. #2
    Phil Weber Guest

    Re: Is refreshing a page in JavaScript the same as posting it back?

    > Is refreshing a page through client-side JavaScript...
    > the same functionally as posting a page back?


    Jason: No. You need to do a form.post in order to get postback behavior.

    Why not pass the desired slide number as a parameter in the querystring?
    e.g.:

    <script language="JavaScript">
    // refreshes the current page every 9 seconds
    var intervalID;
    intervalID = window.setInterval("nextSlide()", 9000);
    function nextSlide()
    {
    currentSlide += 1;
    window.location.href = "http://www.url.com?slide=" +
    currentSlide;
    }
    </script>

    --
    Phil Weber


  3. #3
    Jason Salas Guest

    Re: Is refreshing a page in JavaScript the same as posting it back?

    Nice! I didn't think of that...I was trying to do it all from the ASP.NET
    code. Actually, I did come up with a custom event process of
    incrementing/decrementing through the collection, but it requires the user
    to manually click through the photos, and I'd rather have it work
    automatically.

    Thanks for the tip!


    "Phil Weber" <philweber@hotmail.com> wrote in message
    news:3ea38157$1@tnews.web.devx.com...
    > > Is refreshing a page through client-side JavaScript...
    > > the same functionally as posting a page back?

    >
    > Jason: No. You need to do a form.post in order to get postback behavior.
    >
    > Why not pass the desired slide number as a parameter in the querystring?
    > e.g.:
    >
    > <script language="JavaScript">
    > // refreshes the current page every 9 seconds
    > var intervalID;
    > intervalID = window.setInterval("nextSlide()", 9000);
    > function nextSlide()
    > {
    > currentSlide += 1;
    > window.location.href = "http://www.url.com?slide=" +
    > currentSlide;
    > }
    > </script>
    >
    > --
    > Phil Weber
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center