In this article I will explain with an example, how to display (show) success message after record inserted (Form Submit) in ASP.Net using C# and VB.Net.
This article will illustrate how to display (show) success message using JavaScript alert message box after record inserted (Form Submit) in ASP.Net.
 
 
HTML Markup
The following HTML Markup consists of a standard form with some fields and a Button to submit the form and insert the data into database.
<table border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            Name:
        </td>
        <td>
            <asp:TextBox ID="txtName" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            City:
        </td>
        <td>
            <asp:TextBox ID="txtCity" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
            Country:
        </td>
        <td>
            <asp:TextBox ID="txtCountry" runat="server" />
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
            <asp:Button ID="btnSave" Text="Save" runat="server" OnClick="Save" />
        </td>
    </tr>
</table>
 
 
Display (Show) Success Message after record inserted (Form Submit) in ASP.Net
When the Submit Button is clicked, first the record is inserted into the database and then using ClientScript RegisterStartupScript function, the success message is displayed in JavaScript alert message box.
message – The message to be displayed in the JavaScript Alert Message Box
script – The JavaScript code that will display the Alert message box.
Note: Considering the scope of the article, the code for insertion of record to database is not covered in this article.
 
C#
protected void Save(object sender, EventArgs e)
{
    //Insert record here.
 
    //Display success message.
    string message = "Your details have been saved successfully.";
    string script = "window.onload = function(){ alert('";
    script += message;
    script += "')};";
    ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
}
 
VB.Net
Protected Sub Save(sender As Object, e As EventArgs)
    'Insert record here.
 
    'Display success message.
    Dim message As String = "Your details have been saved successfully."
    Dim script As String = "window.onload = function(){ alert('"
    script &= message
    script &= "')};"
    ClientScript.RegisterStartupScript(Me.GetType(), "SuccessMessage", script, True)
End Sub
 
 
Screenshot
Display (Show) Success Message after record inserted (Form Submit) in ASP.Net
 
 
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.

 
 
Demo
 
 
Downloads