Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • seanrock 241 posts 462 karma points
    Jan 16, 2014 @ 19:16
    seanrock
    0

    PageEvent called twice so my custom icon is added twice

    I'm using the Load page event to add a menu button for a specific content type. However it appears the event is called twice which results in the button being added twice. Any ideas?

     

    private void umbracoPage_Load(object sender, System.EventArgs e)
            {
                umbracoPage page = (umbracoPage)sender;
                string path = page.Page.Request.Path.Replace((umbraco.GlobalSettings.Path + "/"), "");
    
                if (string.Compare(path, "editcontent.aspx"StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return;
                }
    
                ContentPlaceHolder cph = (ContentPlaceHolder)page.FindControl("body");
    
                Control c2 = cph.FindControl("TabView1");
    
                if (c2 == null)
                {
                    return;
                }
                
                ContentControl cc = (ContentControl)c2;
                string docTypeAlias = cc.ContentObject.ContentType.Alias;
    
                if (string.Compare(docTypeAlias, "WarrantyForm"StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return;
                }
    
                TabView tabView = (TabView)c2;
                ArrayList panels = tabView.GetPanels();
                TabPage tabPage = (TabPage)panels[0];
    
                tabPage.Menu.InsertSplitter();
                MenuIconI ni = tabPage.Menu.NewIcon();
    
                ni.ImageURL = "images/editor/approve.gif";
                ni.AltText = "Approve This Warranty Claim";
    
                string approvalFormUrl = umbraco.GlobalSettings.Path + "/plugins/approveform.aspx";
                ni.OnClickCommand = string.Format("document.location.href='{0}'", approvalFormUrl);
            }
  • Marcio Goularte 374 posts 1346 karma points
    Jan 16, 2014 @ 20:45
    Marcio Goularte
    0

    Hi seanrock, try this:

    privatevoid umbracoPage_Load(object sender,System.EventArgs e)
           
    { if(!IsPostBack){
               
    umbracoPage page =(umbracoPage)sender;
               
    string path = page.Page.Request.Path.Replace((umbraco.GlobalSettings.Path+"/"),"");

               
    if(string.Compare(path,"editcontent.aspx",StringComparison.OrdinalIgnoreCase)!=0)
               
    {
                   
    return;
               
    }

               
    ContentPlaceHolder cph =(ContentPlaceHolder)page.FindControl("body");

               
    Control c2 = cph.FindControl("TabView1");

               
    if(c2 ==null)
               
    {
                   
    return;
               
    }
               
               
    ContentControl cc =(ContentControl)c2;
               
    string docTypeAlias = cc.ContentObject.ContentType.Alias;

               
    if(string.Compare(docTypeAlias,"WarrantyForm",StringComparison.OrdinalIgnoreCase)!=0)
               
    {
                   
    return;
               
    }

               
    TabView tabView =(TabView)c2;
               
    ArrayList panels = tabView.GetPanels();
               
    TabPage tabPage =(TabPage)panels[0];

                tabPage
    .Menu.InsertSplitter();
               
    MenuIconI ni = tabPage.Menu.NewIcon();

                ni
    .ImageURL="images/editor/approve.gif";
                ni
    .AltText="Approve This Warranty Claim";

               
    string approvalFormUrl = umbraco.GlobalSettings.Path+"/plugins/approveform.aspx";
                ni
    .OnClickCommand=string.Format("document.location.href='{0}'", approvalFormUrl);
           
    } }
  • seanrock 241 posts 462 karma points
    Jan 17, 2014 @ 09:03
    seanrock
    0

    Marcio Goularte, thanks but that isn't going to work. IsPostBack isn't part of the ApplicationBase which this class inherits from. umbracoPage does inherit from System.Web.UI.MasterPage however the IsPostBack property is always false.

     

  • Marcio Goularte 374 posts 1346 karma points
    Jan 17, 2014 @ 11:51
    Marcio Goularte
    0

    Sorry! I have not seen right. I thought it was the Page_Load event, I replied without reading. Unfortunately I have no idea. Your code looks correct.

Please Sign in or register to post replies

Write your reply to:

Draft