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 scroll, jQuery 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 .
In previous posts I explained call page methods from JSON string in asp.net, jQuery floating div on page scroll, jQuery 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
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. |
|||
|
|||
2 comments :
its not working fine in google crome like internet exploral
Note: Only a member of this blog may post a comment.