In an asp.net windows forms application, in the C# code behind you can use:
MessageBox.Show("Here is my message");
Is there any equivalent in a asp.net web application? Can I call something from the C# code behind that will display a message box to the user?
Example usage of this: I have a button that loads a file in the code behind. When the file is loaded or if there is an error I would like to popup a message to the user stating the result.
Any ideas on this?
if you will include
as namespace then it will conflict . Use
You want to use an Alert. Unfortunately it's not as nice as with windows forms.
Similar to this question here: http://forums.asp.net/t/1461308.aspx/1
There are a few solutions; if you are comfortable with CSS, here's a very flexible solution:
Create an appropriately styled
Panel
that resembles a "Message Box", put aLabel
in it and set itsVisible
property tofalse
. Then whenever the user needs to see a message after a postback (e.g. pushing a button), from codebehind set theLabel
sText
property to the desired error message and set thePanel
'sVisible
property totrue
.Why should not use jquery popup for this purpose.I use
bpopup
for this purpose.See more about this.http://dinbror.dk/bpopup/
You need to reference the namespace
and then add in the code
Just for the records.
Here is a link from Microsoft that I think is the best way to present a MessageBox in ASP.Net
Also it presents choices like Yes and NO.
Instructions on how to get the class from the link working on your project:
Add this code to your aspx page where you want to display the message box:
Add this code on you cs page where you want to decision to be made:
Add this method to your cs page. This is what will be executed when the user clicks Yes. You don't need to make another one for the
NoClick
method.Add a WebUserControl1.ascx file to your root path and add this code to the file:
Add this line on top of your aspx page:
Add this line inside your aspx page (Inside your asp:Content tag if you have one)
Save the image files
1.jpg, 2.jpg, 3.jpg, 4.jpg
from the Microsoft project above into your~/Images/
path.Done
Hope it helps.
Pablo