Jason Evans
Jason Evans

Reputation: 29186

How to stop Umbraco from displaying speech bubble?

For reference, I have asked the same question on the Our Umbraco forum, but thus far have received no response.

We have code running in a Document->AfterSave event which displays a speech bubble:

((BasePage)HttpContext.Current.Handler).speechBubble(BasePage.speechBubbleIcon.error, "Error", "Problem");

we also try

BasePage.Current.ClientTools.ShowSpeechBubble(BasePage.speechBubbleIcon.error, "Error", "Problem");

just in case we are calling the wrong API function for showing the speech bubble.

We do this after validating a document's property and that property is invalid, in order to inform the user that something is wrong.

The problem is that, even though the above code is executed, the Umbraco code that runs after our AfterSave code displays it's own speech bubble, the one that says "Completed" to indicate that the document has been saved. This results in our speech bubble never being displayed at all.

Can someone suggest how we can display a speech bubble that won't be overriden by Umbraco's own calling of speeh bubble please?

Upvotes: 0

Views: 624

Answers (2)

Myster
Myster

Reputation: 18114

You can work round this by injecting your speech bubble later in the page life cycle like so

var page = HttpContext.Current.Handler as Page;
if (page != null)
{
    page.PreRenderComplete += AddAlertBubble;
}

And the AddAlertBubble function is just has what you already have:

void AddAlertBox(object sender, EventArgs e)
{
    umbraco.BasePages.BasePage.Current.ClientTools.ShowSpeechBubble(umbraco.BasePages.BasePage.speechBubbleIcon.error, "Error", "Problem");
}

Upvotes: 1

csharpforevermore
csharpforevermore

Reputation: 1524

You can stop the speech bubble by cancelling the document publishing when your check fails.

     void Document_BeforePublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
     {    
         if(!passed){
             e.Cancel = true;
             ((BasePage)HttpContext.Current.Handler).speechBubble(BasePage.speechBubbleIcon.error, "Error", "Problem");
         }
     } 

Upvotes: 1

Related Questions