Tip for those who put ScriptManager on the Master page

Last post 05-25-2010 9:08 PM by BlakeMcKenna. 35 replies.

Sort Posts:

  • Tip for those who put ScriptManager on the Master page

    07-12-2006, 1:40 PM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171

    One the the important ScriptManager properties that I test all the time is IsInPartialRenderingMode.

    However, because I put my ScriptManager on the Master page, testing the IsInPartialRenderingMode property from apsx page is a pain in the neck, because it forces me to use a "Master.FindControl(...)" every time I want to test it.  And because I always compile with Strict mode, I have to add the CType() as well, making the code pretty awful.

    That's where my tip comes in.

    On the code-behind page of the Master page, I create a read-only property called "IsInPartialRenderingMode", like this:

    Public ReadOnly Property IsInPartialRenderingMode() As Boolean
    	Get
    		Return AtlasScriptManager.IsInPartialRenderingMode
    	End Get
    End Property

    Then, every time I want to test if the page is in partial render mode I use: 

    Master.IsInPartialRenderingMode

    Which is much better than: 

    CType(Master.FindControl("AtlasScriptManager"), Microsoft.Web.UI.ScriptManager).IsInPartialRenderingMode

    And probably much faster too!

    As Scott Guthrie likes to say, "hope this helps."

    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    07-13-2006, 9:30 AM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171
    Has anyone else tried this?  Am I stating the obvious?  (I thought it was a cool technique, but maybe it's commonplace?)
    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    07-13-2006, 2:26 PM
    • Member
      185 point Member
    • IDisposable
    • Member since 04-13-2006, 5:50 PM
    • St. Louis, MO, USA, NA, Earth, Sol, Milky Way
    • Posts 37
    This is cool, thanks!
    http://musingmarc.blogspot.com
  • Re: Tip for those who put ScriptManager on the Master page

    06-27-2007, 4:44 AM
    • Member
      33 point Member
    • fulgeru99
    • Member since 01-24-2005, 2:20 AM
    • Romania
    • Posts 15

    you can get a reference to your scriptmanager very easily like this:

    ScriptManager.GetCurrent([page]) 

  • Re: Tip for those who put ScriptManager on the Master page

    06-27-2007, 6:00 AM
    • Contributor
      4,802 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 3:04 PM
    • Dhaka, Bangladesh
    • Posts 887

    The ScriptManager Contains a Static(Shared in VB) method which returns the Current Instance of the ScriptManager. Just Pass the Current Instance of the Page. For Example:

    if You are in Content Page: Try

    ScriptManager scriptManager = ScriptManageg.GetCurrent(this);

    In User Control, Try:

    ScriptManager scriptManager = ScriptManageg.GetCurrent(this.Page);

    It will always return the ScriptManager no matter how deep your nesting is.

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
  • Re: Tip for those who put ScriptManager on the Master page

    07-10-2007, 6:28 PM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171

    KaziManzurRashid:

    The ScriptManager Contains a Static(Shared in VB) method which returns the Current Instance of the ScriptManager. Just Pass the Current Instance of the Page.

    ....

    That is certainly another way to do it.  However, by keeping the ScriptManager in the Master page, you can greatly simplify your code maintenance.  ESPECIALLY for those of us who have enormous web sites to maintain!

    Another type of Method that developers may want to add to their Master page is a Method to add a service dynamically.  It's also another example of how both methods described here could be useful.  Creating a Master page AddAjaxService() method encapsulates the logic in the Master page, while the GetCurrent() Shared (Static) method of the ScriptManager object would be more direct, but would spread out the logic.

    Thanks very much for the feedback.  There are good uses for both methods.

    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    07-10-2007, 6:41 PM
    • Contributor
      4,802 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 3:04 PM
    • Dhaka, Bangladesh
    • Posts 887
    I am not sure if you are familiar with ScriptManagerProxy. This is class is basically created for content pages where master page has the ScriptManager.
    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
  • Re: Tip for those who put ScriptManager on the Master page

    07-10-2007, 7:00 PM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171

    KaziManzurRashid:
    I am not sure if you are familiar with ScriptManagerProxy. This is class is basically created for content pages where master page has the ScriptManager.

    Of course I'm familiar with ScriptManagerProxy!

    Let's just say that the site I developed is very complex, and requires innovative solutions like I am discussing.  And those solutions need to be highly maintainable, because the site is huge.

    ScriptManagerProxy is great to use in many cases.  You need to recognize that there are people who don't think it's necessarily the best solution in all cases.  It makes life easy for basic sites, that's for sure.

    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    07-10-2007, 7:33 PM
    • Contributor
      4,802 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 3:04 PM
    • Dhaka, Bangladesh
    • Posts 887

    I think the debate was started becasue you mention to have a property "ScriptManager" in Master Page so you can dynamically add various Web Service and Scripts in your content pages and below. and My Recommendation was to use the static method ScriptManager.GetCurrent to get the reference. Correct?

    Let me show you how your solution suffers:

    Say You have a Master Page with scriptmanager and the property you mention. Now your content page contains a User Control which also contains another user control.

    MasterPage
    --ContentPage
    ---UserControl1
    ----UserControl2

    Now say your in the UserControl 2 and you have to refer the script manager of master page, how do you refer it? It needs a lot of property exposing in the whole hierarchy.

    But using ScriptManager.GetCurrent you can get the reference no matter how deep and complex your hierachy is.

    I hope this will make yourself clear that the Ajax team does add this static mathod with valid reason.

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
  • Re: Tip for those who put ScriptManager on the Master page

    07-10-2007, 11:46 PM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171

    KaziManzurRashid:

    I think the debate was started becasue you mention to have a property "ScriptManager" in Master Page so you can dynamically add various Web Service and Scripts in your content pages and below. and My Recommendation was to use the static method ScriptManager.GetCurrent to get the reference. Correct?

    Let me show you how your solution suffers:

    Say You have a Master Page with scriptmanager and the property you mention. Now your content page contains a User Control which also contains another user control.

    MasterPage
    --ContentPage
    ---UserControl1
    ----UserControl2

    Now say your in the UserControl 2 and you have to refer the script manager of master page, how do you refer it? It needs a lot of property exposing in the whole hierarchy.

    But using ScriptManager.GetCurrent you can get the reference no matter how deep and complex your hierachy is.

    I hope this will make yourself clear that the Ajax team does add this static mathod with valid reason.

    Amit,

    I think you're having a hard time understanding what I'm describing.  I am not saying that every property of the ScriptManager should be exposed through the Master page.  I made some very targeted points, and descibed a technique that is very useful for making a few common properties and methods exposed, while keeping the logic inside one page.

    You seem to be stuck on thinking there is one way to do everything.  There are many, many ways, one not necessarily better than another.

    Now, if you go back to the beginning of this thread you will see that it did not start as a topic about exposing the entire ScriptManager.  It is a tip for people who want to expose minimal information, as I described.

    It would be nice if you would not debate this, because you are trying to shoot down alternative programming methods as if there is no value to them, and I don't appreciate it.  I believe if you check my credtials you will find that I know what I am talking about.

    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    07-11-2007, 5:06 AM
    • Contributor
      4,802 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 3:04 PM
    • Dhaka, Bangladesh
    • Posts 887

    I dont think I am having a hard time. My Point is that the tips/recommendation you made is not good at all and suffers in many cases like the above.

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
  • Re: Tip for those who put ScriptManager on the Master page

    07-11-2007, 7:14 AM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171

    KaziManzurRashid:

    I dont think I am having a hard time. My Point is that the tips/recommendation you made is not good at all and suffers in many cases like the above.

    My friend, you have a lot to learn.

    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    07-11-2007, 8:04 AM
    • Contributor
      4,802 point Contributor
    • KaziManzurRashid
    • Member since 03-09-2003, 3:04 PM
    • Dhaka, Bangladesh
    • Posts 887

    Pls comeup with example/Scenario which shows the advantage. Your tips only works in small system where you have few set of pages and controls, not in larger scale apps where you have very complex hierarchy of page and user controls like I mentioned above.

    Every one has to learn even the Isac Newton said "I am only a child playing on the beach, while vast oceans of truth lie undiscovered before me."

    Long Live .NET
    Kazi Manzur Rashid (Amit)
    _________________________
    Web: http //dotnetshoutout.com
    Blog: http://weblogs.asp.net/rashid
    Twitter: http://twitter.com/manzurrashid
  • Re: Tip for those who put ScriptManager on the Master page

    07-11-2007, 8:20 AM
    • Member
      380 point Member
    • speednet
    • Member since 06-24-2005, 3:35 AM
    • Posts 171

    Amit,

    Clearly we cannot come to agreement.  In fact, we stand at exact opposite viewpoints on this, and all the literary quotes in the world will not bridge that divide.

    I hope in the future when someone posts a useful tip to the forums that you will make an attempt to see things from the author's persepctive.  If you disagree so strongly, perhaps you could start your own thread, rather than taking the author's thread down a long, argumentative path.  I believe when people see other contributors being shot down without even an attempt to understand their viewpoint, they themselves are discouraged from posting such tips in the future.

    I would be happy to address questions or comments from others about this topic.  It is a technique that helped me transition from the old Atlas to the new AJAX Extensions with little effort, as it keeps the logic in one place, where it can be changed for the whole app at once.  It is especially nice for large projects.

    http://www.speednet.biz/
  • Re: Tip for those who put ScriptManager on the Master page

    10-17-2007, 10:44 AM
    • Member
      37 point Member
    • KevinC
    • Member since 01-06-2006, 11:59 AM
    • Posts 22

    If there must be an argument of someone else on which 'solution' is the best. Thanks for the answer of KaziManzurRashid, for I was looking for the problem of referring to the scriptmanager in the masterpage, both from contentpages and usercontrols (nested).

    Making the other 'solution' completely obsolete. Why should you do that when there is an easier way to do it? "It works if..." does not do it in my company.

    You are stating to return the value of some method of the scriptmanager from the masterpage to a page below, which is fine by me... But at least use the method GetCurrent along with it, for this is what it is meant for. Don't make it needlessly complex.

Page 1 of 3 (36 items) 1 2 3 Next >