Displaying Message Boxes

  • Thread starter Thread starter Paul Johnson
  • Start date Start date
P

Paul Johnson

Can a message box be displayed using asp.net code? I know there is a
System.Windows.Forms.MessageBox but i cant use it in my web pages, I always
get an error message saying that Windows cannot be found in System
namespace.
 
No, The Windows.Forms.MessagesBox (and all other Windows.Forms.*)
are not working under Web.......

Simply use a Clientside JavaScript or VBScript

JavaScript: alert('Hello');
VBScript: Msgbox "Hello"
 
Producing a MessageBox by the .NET Framework on an ASP.NET page is an
impossibility because messageboxes are a function of the browser, not the
server.

You need to use traditional client-side script to produce a messagebox in
the browser.
 
There is a solution I used in one asp.net application:

In page's html insert hidden field and name it, say,
hidField. Give it attribute runat="server";
in c# (vb) class (code behind) for this page declare this
hidden field like this:

protected System.Web.UI.HtmlControls.HtmlInputHidden
hidField;

Then use its value attribute to give it any message you
need when you need. Say, hidField.Value = "Freaking
message";

Then insert a script function inside of your html,
something like this:

<script>
function checkError()
{
if(document.all.hidField && document.all.hidField.value !
= "")
alert(hidField.value);
hidField.value = "";
}
</script>

And finally add onLoad event (jscript event) to your body
tag in your html:

<body onLoad="checkError();">

Now every time you need to send any message from your c#
(vb) to the client, just assign any string to the hidField
value in your c# (vb).

That's it.

Regards.
 
Back
Top