You are here:   Blogs
Register   |  Login

Search

Minimize

PPG&A Blogs

Minimize
Dec 22

Written by: Phil Porter
12/22/2009 6:12 AM 

Putting the script manager on a master page is a great place to consolidate a common element of an asp.net page that is used across ever page of your asp.net application.  This works well until there is a special need to interact with the script manager.  Fortunately there are ways to interact with the script manager without having to hard code special conditions in the master page which could lead to breaking changes later.  

A situation that comes to mind is when a control is in an update panel and there is a need for the control to do a complete post back.   A simple was to access the script manager on the master page is to get a reference from the current page as in the sample below.

ScriptManager Smgr = ScriptManager.GetCurrent(this.Page);

Now that we have a handle to the script manager we can work with it just as if we were adding our code in the master page.  I usually get the reference in the PreRender event of the pages life cycle.

The next thing is to check and make sure the system could actually find the script manager.  Then we can tell it to register the post back control.  As you can see in the example below it’s a mater of calling the method RegisterPostBackControl and passing.


if (Smgr != null)
{
  Smgr.RegisterPostBackControl(this.btnGenerateQWCFile);
}

In the example above when the user clicks on the button btnGenerateQWCFile it will cause the page to do a full post back.  

Phil

 

Tags:

Archive

Minimize

WARRANTIES

Minimize

SOURCE CODE SAMPLES MAY BE INCLUDED IN SOME BLOGS. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

Other marks and trade names used in this publication are the property of their respective owners.