Webforms equivalent of a Message Box

T

Tom Wild

Hi

Is there an equivalent of the message box that can be used for webforms?
When I try to use a normal message box I get the following error:

"It is invalid to show a modal dialog or form when the application is not
running in UserInteractive mode. Specify the ServiceNotification or
DefaultDesktopOnly style to display a notification from a service
application."

Thanks

Tom
 
K

Kevin Spencer

This might come in handy for some folks. It's a MsgBox function I created
for ASP.Net apps to use:

/// <summary>
/// Adds a JavaScript "alert()" with strMessage to Page Startup
/// </summary>
/// <param name="strMessage">Message to display</param>
public static void MsgBox(string strMessage)
{
string s;
System.Web.UI.Page p;
try
{
if (HttpContext.Current == null) return;
s = "<script type=\"text/javascript\">" +
Environment.NewLine + "<!--" + Environment.NewLine +
"alert('" + strMessage.Replace("\"", "\\\"") + "');" +
Environment.NewLine + "// --></script>";
p = (System.Web.UI.Page) HttpContext.Current.Handler;
if (!(p.IsStartupScriptRegistered("MsgBox")))
p.RegisterStartupScript("MsgBox", s.ToString());
}
catch (Exception ex)
{
HandleError(ex); //Create your own Error Hander
}
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

MsgBox in ASP.NET? 1
Enterprise Logging does nothing on server 5
Weird ASP.NET 2.0 Error 1
Window Services XML Export Error 1
msgbox 4
MsgBox 2
MSGBOX PROBLEM 3
MsgBox Error 1

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top