Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
1.80/5 (5 votes)
See more:
How to display messagebox in ASP.net using C# (Please help)

[Edit - shouting removed]
Posted
Updated 13-Jun-13 2:46am
v2
Comments
[no name] 13-Jun-13 7:27am    
A MessageBox will be displayed on the server, are you sure that is what you want? Why are you screaming at us?

In windows Application you can use :

MessageBox.Show("your message");

In web Applications you can use java script from server side code
Page.ClientScript.RegisterStartupScript(this.GetType(),"scriptkey","alert('your message');");
 
Share this answer
 
Comments
manoj.madhukar1 11-Jul-18 8:47am    
good
add script code in your page:
XML
<script type="text/javascript">
        function Showalert() {
            alert('Call JavaScript function from codebehind');
        }
</script>

here is code for display the alert message... It is similar to msgbox.

<pre>
<div>
<asp:Button ID="btnSubmit" runat="server" Text="Show alert" onclick="btnSubmit_Click"/>
<asp:Button ID="btnClick" runat="server" Text="Call JavaScript Function" onclick="btnClick_Click" />
</div>


I hope this is help for You.
 
Share this answer
 
v2
You can add reference of System.Window.Form, that would give to add MessageBox in your asp.net application, it is good when you are in debug mode mean only you want to test your website. But problems come when you host you host your website, mean production phase.
Better you you javascript.
 
Share this answer
 
Comments
Member 10638568 7-May-14 10:18am    
not possible to add that namespace
Brijesh Kr 3-Jun-14 4:59am    
You need to add reference of System.Windows.Form
Member 11026295 27-Aug-14 4:21am    
But the message box is placed in taskbar. why?
Member 11688204 23-May-17 8:59am    
AX
Response.Write(@"<script language='javascript'>alert('Details saved successfully')</script>");
 
Share this answer
 
There are no of ways to do this.
you van use javascript code inside c# code as
C#
string display = "Message Pop-up!";
            ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);

or use modalpopup extender
as
http://forums.asp.net/t/1900752.aspx/1?Display+success+Message+box+in+asp+net+using+c+[^]
 
Share this answer
 
Comments
Member 13680033 17-Feb-18 12:08pm    
this one works..thanksssssssssssss
Response.Write("<script type=\"text/javascript\">alert('Your Message');</script>");
 
Share this answer
 
VB
Dim myStringVariable1 As String = string.Empty
myStringVariable1 = ("Policy Number:" + ("  "  _
            + (txtPolNo.Text.ToString + ("  " + ("with Issuance office:" + ("  "  _
            + (dropIssOff.Text.ToString + ("  " + "was not found on the database. Please make sure that your inputs are correct."))))))))
ClientScript.RegisterStartupScript(Me.GetType, "myalert", ("alert('"  _
                + (myStringVariable1 + "');")), true)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900