ASP.NET Web Application Message Box
You want to use an Alert. Unfortunately it's not as nice as with windows forms.
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + myStringVariable + "');", true);
Similar to this question here: http://forums.asp.net/t/1461308.aspx/1
How can I display a messagebox in ASP.NET?
@freelancer If you are using ScriptManager then try this code for message..
string script = "alert(\"Hello!\");";
ScriptManager.RegisterStartupScript(this, GetType(),
"ServerControlScript", script, true);
How to show MessageBox on asp.net?
MessageBox doesn't exist in ASP.NET. If you need functionality in the browser, like showing a message box, then you need to opt for javascript. ASP.NET provides you with means to inject javascript which gets rendered and executed when the html sent to the browser's loaded and displayed. You can use the following code in the Page_Load for example:
Type cstype = this.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
{
String cstext = "alert('Hello World');";
cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
}
This sample's taken from MSDN.
Display Success Message Box in ASP.NET C#
MessageBox.Show("Successfully saved", " Student Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
How can I show a message box on a web page before redirect to another web page in asp.net?
You'll want to do the redirect on the client side after the alert:
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('The data was written!'); window.location.replace('Login.aspx');", true);
}
Confirmation message box in webapplication
I think you are going about this the wrong way. You should display this confirmation before posting back, and then only post back if they choose to "Apply".
Using ASP.NET web controls, the Button
control has an OnClientClick
property which can be used to call javascript prior to Http POST:
You could do something like this:
<asp:button id="btn"
runat="server"
Text="Apply"
OnClientClick="return confirm('Are you sure you wish to apply?');"
OnClick="btn_Click" />
Javascript popup message didn't work in asp.net web application using MasterPage
Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Erroe " + myMessage + "');", true);
use this
How to show/display message box in C# asp.net forms?
Use:
string display = "Pop-up!";
ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + display + "');", true);
how to show alert box after successful insert using C#
YES OR NO MessageBox
Buttons, Message Box, and Confirm Box in ASP.NET 3.5
Easiest way to do a message box with an ok button??
How to show MessageBox in ASP.NET (CSASPNETMessageBox)
Message Boxes in ASP.NET (MVC) Web Application
You can use ModelState
for add custom error message
if (String.IsNullOrEmpty(dateSearchBegin) || String.IsNullOrEmpty(dateSearchEnd))
{
ModelState.AddModelError("CustomError", "Both date fields are required");
}
End show in view:
@Html.ValidationMessage("CustomError")
Related Topics
How to Change Another Program's Window's Size
Generic C# Code and the Plus Operator
Wait for a While Without Blocking Main Thread
Get the Final Generated HTML Source Using C# or Vb.Net
Exception Using Copytodatatable with "New {..}" Linq Query
(.1F+.2F==.3F) != (.1F+.2F).Equals(.3F) Why
The Name <...> Does Not Exist in the Namespace Clr-Namespace <...>
When to Use Enums, and When to Replace Them with a Class with Static Members
Starting a Process with Credentials from a Windows Service
Redirecting Output to the Text File C#
Class with Indexer and Property Named "Item"
How to Set Dynamic Value in My Attribute
Crud Operations Using Datagridview, Datatable and Dataadapter - Cannot Add New Row to Datagridview
How to Create Roles in ASP.NET Core and Assign Them to Users