can webparts be loaded for everyone but only edited by admin..code attached

Last post 11-09-2009 9:28 PM by vinz. 5 replies.

Sort Posts:

  • can webparts be loaded for everyone but only edited by admin..code attached

    11-05-2009, 3:32 PM
    • Member
      3 point Member
    • BoostedH23a1
    • Member since 10-19-2009, 3:22 AM
    • Posts 50

    Hey guys i am trying to come up with a way o can make a few of my pages easy to edit just as being admin. what i was thinking is have the user control dropdown thingy hidden for everyone except admin. i have already made the close button to False so they cant close it out. if there is an easier way to do this please by all means let me know. the only time i get the Edit button in my drop down list is when i am on the Default page(only one that has webparts) so i can not edit any other page, even though it is in the <asp.content> div. i a noob so please be gentle. my brain hurts from watching all these tuturials to no avail.

    here is my current default master page .cs

    this is just a part of it, but i would imagine this is what i would edit? i already have roles setup on my page.

    www.frogmoreaeroclub.com

    protected void Page_Init(object sender, EventArgs e)
        {
            

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                foreach (WebPartDisplayMode wpdmDisplayMode in WebPartManager1.SupportedDisplayModes)
                {
                    if (wpdmDisplayMode.IsEnabled(WebPartManager1))
                    {
                        drpDisplayModes.Items.Add(new ListItem(wpdmDisplayMode.Name, wpdmDisplayMode.Name));
                    }
                }
            }
            else
            {
                drpDisplayModes.Visible = false;
            }

  • Re: can webparts be loaded for everyone but only edited by admin..code attached

    11-05-2009, 8:50 PM
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    Have you tried restricting the displaymodes based on roles?

       if (User.IsInRole("Administrators")) {
            WebPartManager1.DisplayMode = WebPartManager.EditDisplayMode();
        }
        else if (User.IsInRole("NormalUsers")) {
            WebPartManager1.DisplayMode = WebPartManager.BrowseDisplayMode();
        }
        else {
            Response.Write("Invalid user");
        }


    "Code,Beer and Music ~ my way of being a programmer"

  • Re: can webparts be loaded for everyone but only edited by admin..code attached

    11-07-2009, 10:28 AM
    • Member
      3 point Member
    • BoostedH23a1
    • Member since 10-19-2009, 3:22 AM
    • Posts 50

     do i replace what i posted with that or something else.

    also another question is am i supposed to be able to edit any content that is inside the content placeholders with data inside the <aspcontent> divs(ie the pages) using this edit feature? if so that is not working. i do not get the Edit drop down in my other pages, only in the default page (currently the only page with webparts). i would love to be able to edit all the pages via logging in as admin.

    here is my default.master.cs (where my manager is)

    using System;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.WebControls;
    using System.Web;

    public partial class MasterPage : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        
        protected void Page_Init(object sender, EventArgs e)
        {
            

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                foreach (WebPartDisplayMode wpdmDisplayMode in WebPartManager1.SupportedDisplayModes)
                {
                    if (wpdmDisplayMode.IsEnabled(WebPartManager1))
                    {
                        drpDisplayModes.Items.Add(new ListItem(wpdmDisplayMode.Name, wpdmDisplayMode.Name));
                    }
                }
            }
            else
            {
                drpDisplayModes.Visible = false;
            }
        }
        protected void drpDisplayModes_SelectedIndexChanged(object sender, EventArgs e)
        {
            WebPartManager1.DisplayMode = WebPartManager1.SupportedDisplayModes[drpDisplayModes.SelectedValue.ToString()];
        }
        protected void Menu1_MenuItemClick(object sender, MenuEventArgs e)
        {

        }
        protected void ClubMenu_MenuItemClick(object sender, MenuEventArgs e)
        {

        }
    }

  • Re: can webparts be loaded for everyone but only edited by admin..code attached

    11-08-2009, 7:40 PM
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    unfortunately the Edit functionality is only applicable for WebParts and not for all the controls that is in the page..

    "Code,Beer and Music ~ my way of being a programmer"

  • Re: can webparts be loaded for everyone but only edited by admin..code attached

    11-09-2009, 6:55 PM
    • Member
      3 point Member
    • BoostedH23a1
    • Member since 10-19-2009, 3:22 AM
    • Posts 50

    ok.. let me tell you what im trying to do, maybe there is an easier way.

    I am trying to make a little sidebar with my current rates for certain items (small list only like 4 things). these change probably quarterly or so, so i would like to be able to edit the webpart. i am in C# and all the examples i have watched are in vb. i would assume i will have to databind this into a table and reference those?

    basicly something like

    <h2>Current Rates</h2>
    Monthly Dues: (price here)
    <h3>Aircraft Rates</h3>
    Cessna 172:  (price here)<br />
    Piper PA-28: (price here)<br />
    <br />



  • Re: can webparts be loaded for everyone but only edited by admin..code attached

    11-09-2009, 9:28 PM
    Answer
    • All-Star
      91,768 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    I.m not really sure if follow but if you are trying to edit and update certain fields within a webpart then you can use UserControl as WebParts. that way you can encorporate controls all together into a single webpart and do the edit and update logic there..Check the post below and find item 5 to get more information on how to create UserControls as WebParts.

    ASP.NET WebPart FAQ

    "Code,Beer and Music ~ my way of being a programmer"

Page 1 of 1 (6 items)