Unable to change WebPartDisplayMode when WebForm uses Master Page

Last post 11-23-2003 4:35 AM by Fredrik N. 4 replies.

Sort Posts:

  • Unable to change WebPartDisplayMode when WebForm uses Master Page

    11-22-2003, 9:25 AM
    • Member
      525 point Member
    • guam-aspdev
    • Member since 08-08-2002, 2:14 AM
    • Guam
    • Posts 111
    • ASPInsiders
    Hi everyone,

    I’ve run into a little snag…I’m hoping it might just be an alpha thing. I’ve been trying to do an integrated example for an article on developing WebParts I’m working on, so I wanted to combine several Whidbey technologies at the same time, to demonstrate 2.0’s ease of migration and also to show how easy it is to actually build and manage something quickly.

    I’m for some reason unable to modify the WebPartDisplayMode of a page when a .ASPX page is using a Master Page. I wrote the code for it, but it won’t seem to take, and on post back, just says in the default Normal mode, instead of going into Design mode or one of the other choices from the WebPartDisplayMode enumeration.

    Here's scenario: I've got a series of user controls contained in a number of WebParts in a Content control on a WebForm. The page has a main header, footer and navigation bar on the left, all 3 of which are served from a Master page to define layout. Without the Content control, it works perfectly, allowing me to toggle between Normal and Design modes. But when I apply the Master Page, it won't change on post back.


    Anyone else run into this?

    Jas


  • Re: Unable to change WebPartDisplayMode when WebForm uses Master Page

    11-22-2003, 7:34 PM
    • Member
      525 point Member
    • guam-aspdev
    • Member since 08-08-2002, 2:14 AM
    • Guam
    • Posts 111
    • ASPInsiders
    Check that...I was able to get the WebParts to get into Design mode, but only by setting the WebPartsDisplayMode enumeration to "Display" in Page_Load. It's probably something with my code, but if anyone has run into this problem, please chime in.

    Jas
  • Re: Unable to change WebPartDisplayMode when WebForm uses Master Page

    11-23-2003, 3:40 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 1:03 AM
    • Sweden
    • Posts 5,334
    It works fine for me.

    I also have some small problem from the beginning. Here is what I have done to make it work;

    I’ve added the WebPartManager into the MasterPage it self.
    I also put the code that changes the mode of the WebPartManager into the MasterPage:


    WebPartManager.Current.SetDisplayMode(WebPartDisplayMode.Edit);


    <asp:linkbutton runat="Server" id="perzonalizeWorkspace" onclick="personalize_Click">Personalize this page</asp:linkbutton>


    void personalize_Click(object sender, System.EventArgs e)
    {
    WebPartManager.Current.SetDisplayMode(WebPartDisplayMode.Edit);
    }

    Maybe you wonder why I put it into the MasterPage. It’s because I will use WebParts in all of my pages and it’s a good place to add it.

    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: Unable to change WebPartDisplayMode when WebForm uses Master Page

    11-23-2003, 3:53 AM
    • Member
      525 point Member
    • guam-aspdev
    • Member since 08-08-2002, 2:14 AM
    • Guam
    • Posts 111
    • ASPInsiders
    Good idea. I considered that, but I only need WebParts in some of my pages, and my Master Page layouts are more universal. I'll keep that in mind.
  • Re: Unable to change WebPartDisplayMode when WebForm uses Master Page

    11-23-2003, 4:34 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 1:03 AM
    • Sweden
    • Posts 5,334
    Here is a code that works fine. I have a WebPartZone in a content control. Is your code similar to this?

    <%@ page language="C#" master="~/default.master"%>
    <%@ register tagprefix="uc1" tagname="myControl" src="~/myControl.ascx" %>

    <script runat="server">

    void edit(object s, EventArgs e)
    {
    WebPartManager.Current.SetDisplayMode(WebPartDisplayMode.Design);
    }

    </script>

    <asp:content contentplaceholderid="content" runat="Server">


    <asp:webpartmanager id="WebPartManager1" runat="server"></asp:webpartmanager>

    <asp:linkbutton onclick="edit" runat="Server">Edit</asp:linkbutton><br />

    <asp:webpartzone id="WebPartZone1" runat="server">
    <zonetemplate>
    <asp:contentwebpart id="ContentWebPart1" runat="server">
    <contenttemplate>
    Test....
    </contenttemplate>
    </asp:contentwebpart>
    </zonetemplate>
    </asp:webpartzone>
    <asp:webpartzone id="WebPartZone2" runat="server">
    <zonetemplate>
    <uc1:mycontrol id="MyControl1" runat="server"></uc1:mycontrol>
    </zonetemplate>
    </asp:webpartzone>
    </asp:content>

    This is something that doesn’t belong to your question and maybe you already knew this: You can create nested master pages, so you can create a main master page that two other master pages inherit. In this way you can create two sub master pages, one that has web part support and one that doesn’t. Like you I have also built a demonstration site that should have pages that doesn’t use web parts and some pages that will use web parts. The purpose is to demonstrate all the new features, including nested master pages.
    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
Page 1 of 1 (5 items)