Server side Message box in ASP.Net
Server side Message box in ASP.Net
Using JavaScript, you can access the dialog boxes while on page loading or after rendering the page content to the browser. There is no way to get a confirmation from the user while you process the functionality through JavaScript. To accomplish this you have to go for a server side message box. Server side message box provides an option to get a confirmation from the user based on some functionality checking, after getting the confirmation from the user click it process the functionality based on user selection.
Read it at the external site...
| R. Arockia Jayaseelan | |
| Intermediate | |
| Language: | VB.NET, Jscript.NET |
| Platform: | Web |
| VS.NET | |
| External link |
Server side Message box in ASP.Net
Message box, it displays a message in dialog box, waits for the user to click the button and returns a value indicating which button is user clicked, based on the user selection the functionality to be performed.
While comparing with windows application, it’s bit hard to implement in web based solutions. At the same time you can achieve this using JavaScript. JavaScript implementations having some limitations like inability to customize the buttons in a message box.
Using JavaScript, you can access the dialog boxes while on page loading or after rendering the page content to the browser. There is no way to get a confirmation from the user while you process the functionality through JavaScript. To accomplish this you have to go for a server side message box.
Server side message box provides an option to get a confirmation from the user based on some functionality checking, after getting the confirmation from the user click it process the functionality based on user selection.
In this article I am not explaining in much more detail about my implementation, here I provide the code for implementation, Hope you understand the implementation with out any problem
After implementing my code you can get Message box like below

Class Implementation
Download "MessageBox.vb" class file and add it into your project. Which explains implementation of message box control class, also do the following page level implementation
Page Implementation
And my .aspx looks like
1. MessageBox.aspx
|
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MessageBox.aspx.vb" Inherits="ASPMessageBox.MessageBox1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>MessageBox</title> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder> <asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 95px; POSITION: absolute; TOP: 99px" runat="server" Text="Click"></asp:Button> </form> </body> </HTML> |
MessageBox.aspx.vb file looks like the following
|
Public Class MessageBox1 Inherits System.Web.UI.Page Protected WithEvents PlaceHolder1 As System.Web.UI.WebControls.PlaceHolder Protected WithEvents Button1 As System.Web.UI.WebControls.Button Dim newBox As MessageBox = New MessageBox() #Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here CheckYesNo() End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click newBox.MessageBoxButton = 3 newBox.MessageBoxTop = 50 newBox.MessageBoxLeft = 150 newBox.MessageBoxWidth = 300 newBox.MessageBoxHeight = 150 newBox.MessageBoxButtonWidth = 50 newBox.MessageBoxIDYes = "yesno" newBox.MessageBoxIDNo = "yesno" newBox.MessageBoxIDCancel = "yesno" newBox.MessageBoxButtonYesText = "Yes" newBox.MessageBoxButtonNoText = "No" newBox.MessageBoxButtonCancelText = "Cancel" newBox.MessageBoxTitle = "Dynamic message box." newBox.MessageBoxMessage = "Do you want to continue?" newBox.MessageBoxImage = "information.gif" PlaceHolder1.Controls.Add(newBox) End Sub Private Sub CheckYesNo() If Request.Form("yesno") = "Yes" Then Response.Write("Button - Yes - Selected") ElseIf Request.Form("yesno") = "No" Then Response.Write("Button - No - Selected") ElseIf Request.Form("yesno") = "Cancel" Then Response.Write("Button - Cancel - Selected") End If End Sub End Class |
Note: Those who are not able to download MessageBox.vb, click the link http://www.dnzone.com/ShowDetail.asp?NewsId=861
R.Arockia Jayaseelan
* Having 6+ Years of experience in Client Server and Web related Technologies.
* Working as a Software Engineer, USA.
User Reviews
Total of 21 reviewsI want to know how to implement
Written by Rajasekar Natarajan on August 12, 2010Hi Jayaseelan, This Rajasekar from Salem, Tamilnadu. I'm new to .net. so, unable to use this code becoz i know how to use it. I copied all these files into messagebox.aspx and messagebox.aspx.vb. Then I tried to running but it throws the error in ...
Great control but I cant get it to work under a masterpage.
Written by Mike Schuch on August 4, 2010I love this control but I cann't seem to get it to work on a page that has a MasterPage selected.When call the MessageBox from a standalone page with a ScriptManager and a Update panel the control works perfectly.When I try to call it from a page ...
Regarding Message box
Written by prakash k on January 2, 2009Hi friends This code is working fine.but the problem is i can able to navigate or use the back side of the mesage box(web page). so please can u give some suggestion to block the page... Thanks Prakash
Works great - problem with appearing behind controls fixed.
Written by Richard Padden on January 8, 2008This code works very well, thanks. The problem people have been having with the message box appearing behind the other controls on the page can be fixed by changing that last line to: writer.AddAttribute(HtmlTextWriterAttribute.Style, 'Z-INDEX: ...
thanx for replying
Written by priya s on December 18, 2007hi thanx a lot for replying but that does not solve my problem i will explain u in deep i have datagrid with checkboxes when user want to delete some records he has to tick the check boxes and then click on delete button the delele button has ...
i need client side message box
Written by priya s on December 17, 2007hi ur program for server side message box is excellent but i want a client side me message box that will return me users reply depending on this reply i want to call a function written on .cs file plzzzzzz help if u can any reply will be ...
Wonderful
Written by Hani Naiem on January 25, 2007Dear Sir I like your tool very much I implemented it in my asp application but it is shown behind my listboxes and drop down lists! How can I display it in front of all my controls Regards
RE: message box CENTER
Written by R.Arockia Jayaseelan on June 13, 2006Modify the below lines newBox.MessageBoxTop = 50 newBox.MessageBoxLeft = 150 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click newBox.MessageBoxButton = 3 ...





