admin管理员组

文章数量:1326641

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?

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?

Share Improve this question asked Nov 1, 2010 at 15:53 HinekHinek 9,73912 gold badges54 silver badges75 bronze badges 3
  • 2 Is this the jQuery MsgBox or something else? Have you tried the standard javascript alert()? Do you get any error on the page, or is the code just not executed at all? – Peter Jacoby Commented Nov 2, 2010 at 2:52
  • alert() works, thanks. But I'm looking for something similar to the SharePoint standard message boxes (like when you're trying to delete a list) – Hinek Commented Nov 2, 2010 at 7:59
  • wait, I just saw, SharePoint actually uses alert() and confirm() for this ... ok, never mind ... @Peter Jacoby, if you post my snipped and replace MsgBox with alert, I will accept the answer. – Hinek Commented Nov 2, 2010 at 8:02
Add a ment  | 

1 Answer 1

Reset to default 2

From the ments 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);

本文标签: cHow to popup a message box in SharePoint 2010Stack Overflow