Multiple Context Menus in a Web Part

3 posts, 0 answers
  1. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 05 Aug 2008 Link to this post

    Hi,
    I am trying to add multiple context Rad menus in a WebPart but for some reason when I render the menus in the Render method, the only menu that works is the first menu that is added. I have checked all the ID's and targets and they are set properly. A colleague has tried to create 2 separate menus on a test site and is getting the same problem as me. Do you know what the problem could be?

    I have tried a link that was posted from a previous thread but it does not work. This is the link: Adding multiple menus on a single page (ID# 406)



    Thank You,
    Alex
  2. Anil
    Anil avatar
    58 posts
    Member since:
    Nov 2007

    Posted 06 Aug 2008 Link to this post

    Hi Alex,

    Can you please supply some more details about your problem. the link you specified is not working, i guess. how are the two menus placed in the page?

    Thanks
    Anil

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 06 Aug 2008 Link to this post

    Hi Anil,

    This is the code of my menus:

    protected

    override void CreateChildControls()

    {

    base

    .CreateChildControls();

    radList = setMenus(wssUser1);


    for

    (int i = 0; i < rosterCount; i++)

    {

    Controls.Add((

    RadContextMenu)radList[i]);

    }

    profileImage = new Image();

    profileImage.ImageUrl =

    "_layouts/1033/tdsb_aw/images/mysiteplaceholder.JPG";

    }

    protected

    override void OnInit(

    EventArgs e)

    {

    base.OnInit(e);

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

    if (scriptManager == null)

    {

    scriptManager =

    new ScriptManager();

    scriptManager.ID =

    "scriptManager1";

    //scriptManager.EnablePartialRendering = true;

    Controls.AddAt(0, scriptManager);

    }

    mainUpdatePanel =

    new RadAjaxPanel();

    mainUpdatePanel.ID =

    "mainUpdatePanel";

    mainUpdatePanel.LoadingPanelID =

    "myLoadingPanel";

    mainUpdatePanel.EnableAJAX =

    true;

    this.Controls.Add(mainUpdatePanel);

    EnsurePanelFix();

    }


    //This method is the one that sets the targets and ID's of all the menus I am using
    //I am pretty sure that this method is correct because when I print out all of the ID's and  targets are assigned correctly.

    protected ArrayList setMenus(string[] wssUser1)

    {

    try

    {

    //Gets the number of students in the class roster to be used for displaying the menu

    //////////////////////////////////////////////////////////////////////////////////////////////

    SPWeb curweb = SPContext.Current.Web;

    SPPropertyBag curwebpropbag = curweb.Properties;

    ClassRosterBL crBLL = new ClassRosterBL();

    DataTable crDT = (DataTable)crBLL.GetClassRoster(curwebpropbag[Constants.propertyBagSchoolCode], curwebpropbag[Constants.propertyBagClassCode]);

    this.rosterCount = crDT.Rows.Count;

    //////////////////////////////////////////////////////////////////////////////////////////////

    radList =

    new ArrayList();

    controlTargetList =

    new ContextMenuControlTarget[rosterCount];

    String menuID ="";

    for (int i = 0; i < rosterCount; i++)

    {

    RadContextMenu radMenu = new RadContextMenu();

    radMenu.ID =

    "radMenu_" + i.ToString();

    radMenu.Skin =

    "Vista";

    controlTargetList[i] =

    new ContextMenuControlTarget();

    controlTargetList[i].ControlID =

    "profileImage_" + i.ToString();

    radMenu.Targets.Add(controlTargetList[i]);

    RadMenuItem studentInfo = new RadMenuItem();

    studentInfo.Text = wssUser1[i];

    radMenu.Items.Add(studentInfo);

    radList.Add(radMenu);

    menuID += radMenu.ID.ToString() +

    ", " + controlTargetList[i].ControlID.ToString();

    }

    menuID +=

    "Number of items: " + radList.Count;

    throw new Exception(menuID);

    }

    catch(Exception e)

    {

    exMsg += e.Message;

    }

    return radList;

    }


    //This renders the control to all of the menus
    // I think this is where the problem is becuase if I render the menus manually in a different order I noticed that still only the first menu that is being rendered is visible when I run the page.

    protected

    override void RenderContents(System.Web.UI.HtmlTextWriter writer)

    {

    for

    (int i = 0; i < rosterCount; i++)

    {

    RadContextMenu tempMenu = (RadContextMenu)radList[i];

    tempMenu.RenderControl(writer);

    }

    for (int i = 0; i <= newRows.Length - 1; i++)

    {

    profileImage.ID = "profileImage_"+ i.ToString();

    profileImage.RenderControl(writer);

    }

    }


    Plaese let me know as soon as possible if you can determine what's wrong.

    Thank You,
    Alex

Back to Top