views:

217

answers:

2

Hi,

I am working in ASP.net with .Net Framework 2.0 and VS 2008 Team System

I have a master page page and n number of content pages. On the master page i have put a ScriptManager tag and on content page I have an UpdatePanel. But whenever and event like button click is fired form the content page, whole page is post backed. How do i solve this?

+1  A: 

You can get access to the ScriptManager object of the page through GetCurrent() method.

This code accesses the ScriptManager in the Master page from content page (adding a button control btnSubmit as an Asynchronous control):

protected void Page_Load(object sender, EventArgs e)
{
  ScriptManager _scriptMan = ScriptManager.GetCurrent(this);
  _scriptMan.RegisterAsyncPostBackControl(this.btnSubmit);
}

But, I would simply move the ScriptManager from the MasterPage to each content page because then you wouldn't have to do this.

BenB
+1  A: 

It will depend on how you have set up your UpdatePanel.

The key things to look at are:

  • The UpdateMode property of the UpdatePanel
  • The ChildrenAsTriggers property of the UpdatePanel
  • The UpdatePanel's Triggers collection

For example, if you just want the panel to be updated on a single button press go for:

  • UpdateMode=Conditional
  • ChildrenAsTriggers=False
  • And add the button to the UpdatePanel's Triggers collection

Or if you want all controls within the panel to trigger a partial postback then just set ChildrenAsTriggers=True and don't use the Triggers collection.

This MSDN article describes the above properties in more detail.

HullCitySteve

related questions