How to open/set the message box on web site in asp.net c#
In this article, I have pop up the message box using
the code behind in c# language.
Design:-
Source
code:-
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="messagebox.aspx.cs" Inherits="messagebox"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnmessage" runat="server" onclick="btnmessage_Click"
Text="click here for message box" />
</div>
</form>
</body>
</html>
Code
behind (C#):-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
public partial class messagebox : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
protected void btnmessage_Click(object
sender, EventArgs e)
{
Messagebox("Welcome
in Code Solution");
}
private void Messagebox(string
Message)
{
Label
lbMessageBox = new Label();
lbMessageBox.Text =
"<script
language='javascript'>" + Environment.NewLine
+
"window.alert('"
+ Message + "')</script>";
Page.Controls.Add(lbMessageBox);
}
}
Out Put:-
How to open/set the message box on web site in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
12:31:00 PM
Rating:
No comments: