views:

674

answers:

4

I'm experimenting with some AJAX now. I have a custom control which appears on my masterpage in which there is an update panel and a timer. The timer fires and the panel updates and everything is dandy. Except that there are some operations that I don't want it to perform on every refresh. It seems like the entire page lifecycle happens with each refresh. There are variables I want to set, and keep their value on the refresh. Is there a way to make it perform ONLY what's in the timer_tick call?

A: 

UpdatePanels always force the entire page to refresh. If you want only a certain portion of the page to be processed (and it's a fixed size) then you could try using an iframe.

Alternatively, if you want to save the variables you can either put them in ViewState or SessionState so that they are persisted between postbacks

Matthew Steeples
+1  A: 

You could take a look at Request["__EVENTTARGET"] in the page load event to see what control caused the postback. If it's the timer control, jump out of the function.

Assuming your timer is called "refreshtimer":

protected void Page_Load(object sender, EventArgs e)
{
   if (Request["__EVENTTARGET"] == "refreshtimer")
   {
       return;
   }
   // etc
René
+2  A: 

Not sure what what an AJAX.Net post back looks like to, But I usually protect my other controls and content by checking for post back;

protected void Page_Load(object sender, EventArgs e)
{

     // if its a post back then my controls should already be setup... 
     if (!Page.IsPostBack)
     {
          InitControlData();
     }    
}

and then it should fall thru to your event handling?

protected void timer_tick(object sender, EventArgs e)
{
    // Do my Ajaxy work~
}
BigBlondeViking
A: 

This is not possible with UpdatePanels... the entire page will go through the entire lifecycle. As others mentioned, you can limit the processing that happens by using IsPostBack or ScriptManager's IsInAsyncPostBack, but ultimately this is not going to be a great solution for complex pages.

However, you can use Page Methods to execute just one static method in your page, but you'll have to make the Javascript call yourself and update the UI. Here are some examples:

chaiwalla