Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Show (Display) Alert Message Box from Code Behind in Asp.net using C#, VB.NET

Mar 3, 2015
Introduction

Here I will explain how to show alert message box 
from code behind in asp.net using c# and vb.net or display alert message from code behind in asp.net using c# and vb.net.

Description:

In previous posts I explained call page methods from JSON string in asp.net, jQuery floating div on page scrolljQuery generate years dropdown dynamically, asp.net Google currency converter and many articles relating to
gridview, asp.net, c#. Now I will explain how to show alert message box from code behind in asp.net using c# and vb.net .

Generally if we want to show alert message from code behind we will write the code like as shown below

C#.NET

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('This alert from code behind');", true);

VB.NET

ClientScript.RegisterStartupScript(Me.[GetType](), "myalert", "alert('This alert from code behind');", True)
Suppose if you want check above code with example write the following code in your aspx page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>show alert message in asp.net from code behind</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnClick" Text="Click" runat="server" onclick="btnClick_Click" />
</div>
</form>
</body>
</html>

Now in code behind we need to write the code as like shown below

C#.NET Code

using System;

public partial class ShowAlertMessage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnClick_Click(object sender, EventArgs e)
    {
        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('This alert from code behind');", true);
    }
}
VB.NET Code


Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    End Sub
    Protected Sub btnClick_Click(ByVal sender As Object, ByVal e As EventArgs)
        ClientScript.RegisterStartupScript(Me.[GetType](), "myalert", "alert('This alert from code behind');", True)
    End Sub

End Class

Demo


Show Alert Message in Asp.net from Code behind in C#, VB.NET

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

2 comments :

Dileep Yadav said...
This comment has been removed by the author.
Unknown said...

its not working fine in google crome like internet exploral

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.