Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is refreshing a ASP.NET control w/JavaScript the same as posting back?

Status
Not open for further replies.

jasonsalas

IS-IT--Management
Jun 20, 2001
480
GU
Hi everyone,

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

<script language=&quot;JavaScript&quot;>
// refreshes the current page every 9 seconds
var intervalID;
intervalID = window.setInterval(&quot;nextSlide()&quot;,9000);
function nextSlide()
{
document.execCommand(&quot;Refresh&quot;);
}
</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[&quot;nextSlide&quot;];
arrSlide[0] = // display contents;
ViewState[&quot;nextSlide&quot;] = currentSlide + 1;

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

//nth page load:
int currentSlide = (int)ViewState[&quot;nextSlide&quot;];
arrSlide[n] = // display contents;
ViewState[&quot;nextSlide&quot;] = 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
 
&quot;Refresh&quot; is not a post back.

Only a document.forms[0].submit(); does a post back, since that actually submits the form.

Any refresh, reload, Response.Redirect, Server.Transfer (the two latter being server side) does not do a post back, and does not persist ViewState

So conversely:

document.forms[0].submit();

will do a postback, and will persist ViewState.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Thanks a lot! A JavaScript guru I'm not, so this really came in handy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top