![]() |
Web Development »
ASP.NET »
General
License: The GNU General Public License (GPL)
ASP.Net C# MessageBoxBy Syed M HussainThis article explains how to create a messagebox class to use in web applications |
CSS, HTML, ASP, ASP.NET
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Website With MessageBox Interface
.page_dimmer
{
position:fixed;
height:100%;
width:100%;
top:0px;
left:0px;
background-color:#000000;
filter:alpha(opacity=50);
-moz-opacity:.50;
opacity:.50;
z-index:50;
}
.msg_box_container
{
position:fixed;
background-color:#888888;
border:1px solid #999999;
z-index:50;
left:20%;
right:20%;
top:20%;
}
<style>
.page_dimmer
{
position:fixed;
height:100%;
width:100%;
top:0px;
left:0px;
background-color:#000000;
filter:alpha(opacity=50);
-moz-opacity:.50;
opacity:.50;
z-index:50;
}
.msg_box_container
{
position:fixed;
background-color:#888888;
border:1px solid #999999;
z-index:50;
left:20%;
right:20%;
top:20%;"
}
</style>
<div class="page_dimmer" id="pagedimmer"> </div>
<div class="msg_box_container" id="msgbox">
<table width="100%">
<tr>
<td colspan="2">[TITLE]</td>
</tr>
<tr>
<td>[ICON]</td>
<td>[MESSAGE]</td>
</tr>
<tr>
<td colspan="2"><input type="Button" value="OK"></td>
</tr>
</table>
</div>
document.getElementById('page_dimmer')
document.getElementById('msgbox')
document.getElementById('pagedimmer').style.visibility = 'hidden'
document.getElementById('msgbox').style.visibility = 'hidden'
<style>
.page_dimmer
{
position:fixed;
height:100%;
width:100%;
top:0px;
left:0px;
background-color:#000000;
filter:alpha(opacity=50);
-moz-opacity:.50;
opacity:.50;
z-index:50;
}
.msg_box_container
{
position:fixed;
background-color:#888888;
border:1px solid #999999;
z-index:50;
left:20%;
right:20%;
top:20%;"
}
</style>
<div class="page_dimmer" id="pagedimmer"> </div>
<div class="msg_box_container" id="msgbox">
<table width="100%">
<tr>
<td colspan="2">[TITLE]</td>
</tr>
<tr>
<td>[ICON]</td>
<td>[MESSAGE]</td>
</tr>
<tr>
<td colspan="2"><input type="Button" value="OK"
onClick="document.getElementById('pagedimmer').style.visibility = 'hidden';
document.getElementById('msgbox').style.visibility = 'hidden'"></td>
</tr>
</table>
</div>
Notice the OnClick event in the input tag?
ASP.Net C# Custom Message Box
It is now time to develop a reusable message box class. Now that we know how to set up a message box, we can easily begin to develop a custom C# class to do away with all the hassle of having to write the code every time we want to use it. At this point many of you might have some ideas of how to develop the class your self. But rather than shooting off to write the code, stick around and read a little more.
The approach I have taken to develop the message box class is quite simple. The class consists of six public methods one of which returns a string. They are as follows:
public void SetTitle(string msg_title)
public void SetIcon(string msg_icon)
public void SetMessage(string msg_message)
public void SetOKButton(string msg_button_class)
public void AddButton(string msg_button)
public string ReturnObject()
<div style="position:fixed;height:100%;width:100%;top:0px;left:0px;
background-color:#000000;filter:alpha(opacity=55);-moz-opacity:.55;opacity:.55;z-index:50;"
id="pagedimmer"> </div>
<div style="position:fixed;background-color:#888888; border:1px solid #999999; z-index:50; left:20%;
right:20%; top:20%;" id="msgbox">
<div style="margin:5px;">
<table width="100%" style="background-color:#FFFFFF; border:1px solid #999999;">
<tr>
<td colspan="2" style="font-family:tahoma; font-size:11px; font-weight:bold;
padding-left:5px; background-image: url(msg_title_1.jpg); color:#FFFFFF; height:22px;">[TITLE]</td>
</tr>
<tr>
<td style="width:100px; text-align:center;">[ICON]</td>
<td style="font-family:tahoma; font-size:11px;padding-left:5px;">[MESSAGE]</td>
</tr>
<tr>
<td colspan="2" style="border-top:1px solid #CCCCCC; padding-top:5px;text-align:right;">[BUTTONS]</td>
</tr>
</table>
</div>
</div>
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Web;
using System.Web.UI;
public class MessageBox
{
private string strLine;
private StringBuilder msgbox;
private StreamReader readtemplte;
private string msgbox_title = "";
private string msgbox_icon = "";
private string msgbox_message = "";
private string msgbox_ok_button = "";
private string msgbox_buttons = "";
private ArrayList msgbox_button;
public MessageBox(string tpl_path)
{
readtemplte = new StreamReader(tpl_path);
msgbox = new StringBuilder();
msgbox_button = new ArrayList();
while ((strLine = readtemplte.ReadLine()) != null)
{
msgbox.Append(strLine);
}
}
public void SetTitle(string msg_title)
{
this.msgbox_title = msg_title;
}
public void SetIcon(string msg_icon)
{
this.msgbox_icon = "<img src=\"" + msg_icon + "\">";
}
public void SetMessage(string msg_message)
{
this.msgbox_message = msg_message;
}
public void SetOKButton(string msg_button_class)
{
this.msgbox_ok_button = "<input type=\"button\" value=\"OK\" class=\""
+ msg_button_class +
"\" onClick=\"document.getElementById('pagedimmer').style.visibility = 'hidden';"
+ "document.getElementById('msgbox').style.visibility = 'hidden';\">";
}
public void AddButton(string msg_button)
{
msgbox_button.Add(msg_button);
}
public string ReturnObject()
{
int i=0;
while (i < msgbox_button.Count)
{
msgbox_buttons += msgbox_button[i] + " ";
i++;
}
msgbox.Replace("[TITLE]", this.msgbox_title);
msgbox.Replace("[ICON]", this.msgbox_icon);
msgbox.Replace("[MESSAGE]", this.msgbox_message);
msgbox.Replace("[BUTTONS]", msgbox_buttons + this.msgbox_ok_button);
return msgbox.ToString();
}
}
using System;
using System.Text;
using System.Web;
using System.Web.UI;
public class MessageBoxButton
{
private string msg_button = "";
public MessageBoxButton(string btnValue)
{
msg_button = "<input type=\"button\" value=\"" + btnValue + "\"";
}
public void SetClass(string btnClass)
{
msg_button += " class=\"" + btnClass + "\"";
}
public void SetLocation(string btnLocation)
{
msg_button += " onClick=\"window.location='" + btnLocation + "'\"";
}
public string ReturnObject()
{
return msg_button += ">";
}
}
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 27 Apr 2008 Editor: Chris Maunder |
Copyright 2008 by Syed M Hussain Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |