Hinek
Hinek

Reputation: 9739

How to popup a message box in SharePoint 2010

I built a control with a RenderingTemplate for a custom ContentType. It contains additional buttons. If the code behind one button fails, I want to inform the user with a message box.

I tried

string script = "<script language='javascript'>MsgBox('" + errorMessage + "')</script>";
Page.ClientScript.RegisterClientScriptBlock(GetType(), "Register", script);

But it doesn't show and I can't find the javascript code in the rendered page. What am I doing wrong? Is there a special SharePoint message box class in SharePoint 2010?

Upvotes: 2

Views: 22649

Answers (1)

Peter Jacoby
Peter Jacoby

Reputation: 2416

From the comments it sounds like a simple change from MsgBox to alert will work for you. So you would just need the code to slightly modified to:

string script = "<script language='javascript'>alert('" + errorMessage + "')</script>";
Page.ClientScript.RegisterClientScriptBlock(GetType(), "Register", script);

Upvotes: 2

Related Questions