Click here to Skip to main content
11,479,841 members (47,011 online)
Click here to Skip to main content

Server Side MessageBox

, 19 Sep 2005 153.2K 2.8K 105
Rate this:
Please Sign up or sign in to vote.
A web (modal) messagebox without popup.

Sample Image

Sample Image

Introduction

As web developers, we always need model windows. But the simplest model window that comes from JavaScript has a problem: "Popup Blockers". You can write window.showModalDialog(...) in script, but what next?

My component, a web message box is a customizable modal dialog for ASP.NET 2.0, but not a popup and not a new window. It appears at the top of all objects and hides the others, so the other controls can not be clicked.

Background

The idea is very simple. In m control, I have some panels (<div>) and their z-indexes. I open a transparent panel at the top of all elements. So I prevent them being clicked. Then, I need a few new panels for the messagebox and some scripting and styling to show them.

The control has three events:

  • Btn1Clicked
  • Btn2Clicked
  • Btn3Clicked

Two styles:

  • msg.MessageBoxStyle.Violet
  • msg.MessageBoxStyle.Blue

And four icons:

  • msg.MessageBoxIcons.Exclamation
  • msg.MessageBoxIcons.Asteriks
  • msg.MessageBoxIcons.Question
  • msg.MessageBoxIcons.None

You can edit the visual affects by editing the InitializeIcon and InitializeStyle functions in Mbox.ascx.cs.

Using the control

Only thing you should do is add the Mbox.ascx user control and the Resources folder to your project. And then drag & drop the user control to your web form.

Add the following code to your default.aspx or whatever your file is..

protected void Page_Load(object sender, EventArgs e)
{   //bind the events to messagebox buttons...
    Mbox1.Btn1Clicked += new EventHandler(Mbox1_Btn1Clicked);
    Mbox1.Btn2Clicked += new EventHandler(Mbox1_Btn2Clicked);
}
void Mbox1_Btn2Clicked(object sender, EventArgs e)
{
    Response.Write("2nd button clicked");
}

void Mbox1_Btn1Clicked(object sender, EventArgs e)
{
    Response.Write("1st button clicked");
}
//Show methods and their overloads...
protected void Button1_Click(object sender, EventArgs e)
{
    Mbox1.Show("hede", "hodo");
}
protected void Button2_Click(object sender, EventArgs e)
{
    Mbox1.Show("My test message", "Warning", "OK", "Cancel", null);
}
protected void Button3_Click(object sender, EventArgs e)
{
    Mbox1.Show("My test message", "Warning", "OK", "Cancel", null, 
                                 msg.MessageBoxIcons.Exclamation);
}
protected void Button4_Click(object sender, EventArgs e)
{
    Mbox1.Show("My test message", "Warning", "OK", "Cancel", "Retry", 
               msg.MessageBoxIcons.Exclamation,msg.MessageBoxStyle.Violet);
}

I will not tell you more about this message box. I told you the logic behind it. A little effort will be enough to understand the code.

Points of Interest

The next version of the product will be a window-like popup control, but of course not a popup. It will be available soon... For bug reports and suggestions, I will wait for your mails at ozuolmez@msn.com.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Kivanc Ozuolmez
Software Developer
Netherlands Netherlands
No Biography provided

Comments and Discussions

 
QuestionMessage Box Pin
swami samarth19-Apr-12 4:15
memberswami samarth19-Apr-12 4:15 
SuggestionRe: Message Box Pin
WebBHTAN22-Dec-13 5:58
memberWebBHTAN22-Dec-13 5:58 
GeneralMy vote of 5 Pin
manoj kumar choubey7-Feb-12 22:39
membermanoj kumar choubey7-Feb-12 22:39 
QuestionCool Thanks :) Pin
direkt12330-Jul-11 10:02
memberdirekt12330-Jul-11 10:02 
AnswerRe: Cool Thanks :) Pin
WebBHTAN22-Dec-13 5:58
memberWebBHTAN22-Dec-13 5:58 
GeneralMy vote of 5 Pin
shoban_gmail25-Feb-11 8:47
membershoban_gmail25-Feb-11 8:47 
Questiongrey out background??? Pin
simpa20-Apr-10 6:46
membersimpa20-Apr-10 6:46 
AnswerRe: grey out background??? Pin
simpa4-Mar-11 12:10
membersimpa4-Mar-11 12:10 
GeneralCool But.... Pin
sinister2318-Jan-10 23:56
membersinister2318-Jan-10 23:56 
GeneralCool But.... Pin
sinister2318-Jan-10 23:56
membersinister2318-Jan-10 23:56 
Generalwith Net 3.5 Pin
jtorresrios8-Sep-09 7:00
memberjtorresrios8-Sep-09 7:00 
GeneralWorking Example Pin
mayurmv4-Sep-08 6:07
membermayurmv4-Sep-08 6:07 
GeneralDoesn't work in FireFox [modified] Pin
emanlee17-Jul-08 4:49
memberemanlee17-Jul-08 4:49 
GeneralRe: Doesn't work in FireFox Pin
chankl7827-Jul-08 21:40
memberchankl7827-Jul-08 21:40 
AnswerSolution: Doesn't work in FireFox Pin
WebBHTAN22-Dec-13 5:55
memberWebBHTAN22-Dec-13 5:55 
GeneralTeşekkür... Pin
Member 353699911-Mar-08 6:04
memberMember 353699911-Mar-08 6:04 
Generalsession ends Pin
aapke_leeye27-Feb-08 1:18
memberaapke_leeye27-Feb-08 1:18 
GeneralDont´function Ajax (Atlas) Pin
psuporte4-Jul-07 7:26
memberpsuporte4-Jul-07 7:26 
QuestionMoving the MessageBox [modified] Pin
ageltzer7-Jun-07 5:54
memberageltzer7-Jun-07 5:54 
GeneralProblem with Master pages Pin
Pablopablo21-Aug-06 1:39
memberPablopablo21-Aug-06 1:39 
GeneralRe: Problem with Master pages Pin
someone from the earth8-Dec-06 1:15
membersomeone from the earth8-Dec-06 1:15 
QuestionDoes not work properly after publishing the WEB site Pin
Rohan Chandratileka9-May-06 20:59
memberRohan Chandratileka9-May-06 20:59 
AnswerRe: Does not work properly after publishing the WEB site Pin
britneyssssers7-Sep-06 13:52
memberbritneyssssers7-Sep-06 13:52 
Generalproblem in combination with user control Pin
hornox27-Apr-06 3:57
memberhornox27-Apr-06 3:57 
GeneralRun with Master page Pin
plumgrand20-Apr-06 15:48
memberplumgrand20-Apr-06 15:48 
this is a prefect control, but it cannot run with master page. The reason is system cannot get the handle of the Element Client ID in Master page.

so just a little update of javascript, this control can run in Master page correctly, a example as follow:

original code:

gPopupMask = document.getElementById(ControlName + "_popupMask");

update code:

gPopupMask = document.getElementById("<%=popupMask.ClientID %>");

like this, update every sentence in source code, u can get a perfect control worked with Master page.



eric
GeneralRe: Run with Master page Pin
theboton29-May-06 4:02
membertheboton29-May-06 4:02 
GeneralRe: Run with Master page Pin
precozzi14-Aug-06 3:34
memberprecozzi14-Aug-06 3:34 
GeneralRe: Run with Master page Pin
elpguap999918-Aug-06 12:00
memberelpguap999918-Aug-06 12:00 
GeneralRe: Run with Master page Pin
PKoshti5-Sep-06 3:49
memberPKoshti5-Sep-06 3:49 
GeneralRe: Run with Master page Pin
jolero_198322-Jun-07 7:34
memberjolero_198322-Jun-07 7:34 
QuestionRelocation the Message window Pin
rchokler3-Apr-06 7:24
memberrchokler3-Apr-06 7:24 
GeneralDoes not work in contentplaceholder Pin
Nick Red5 Brown16-Dec-05 5:00
memberNick Red5 Brown16-Dec-05 5:00 
GeneralRe: Does not work in contentplaceholder Pin
jolero_198322-Jun-07 7:36
memberjolero_198322-Jun-07 7:36 
GeneralRe: DOES work with contentplaceholder Pin
ytmu00927-Jul-07 6:03
memberytmu00927-Jul-07 6:03 
GeneralThe Greatest..! Pin
stilton@cheese.com25-Oct-05 2:01
memberstilton@cheese.com25-Oct-05 2:01 
GeneralRe: The Greatest..! Pin
John Sibly7-Apr-06 7:12
memberJohn Sibly7-Apr-06 7:12 
GeneralNot Working for me Pin
Rak_i25-Oct-05 1:26
memberRak_i25-Oct-05 1:26 
GeneralRe: Not Working for me Pin
Kivanc Ozuolmez25-Oct-05 1:33
memberKivanc Ozuolmez25-Oct-05 1:33 
GeneralNo Work Pin
Jan Waiz14-Oct-05 5:19
memberJan Waiz14-Oct-05 5:19 
GeneralRe: No Work Pin
Toasty014-Oct-05 5:49
memberToasty014-Oct-05 5:49 
QuestionWhat about a live demo or ASP.NET 1.1 version? Pin
ManuDev28-Sep-05 13:41
memberManuDev28-Sep-05 13:41 
GeneralUser CSS Pin
Sean Feldman28-Sep-05 5:49
memberSean Feldman28-Sep-05 5:49 
GeneralRe: User CSS Pin
Kivanc Ozuolmez28-Sep-05 6:16
memberKivanc Ozuolmez28-Sep-05 6:16 
GeneralDoes it cope with dropdowns lists in IE Pin
tony_bbc28-Sep-05 1:48
membertony_bbc28-Sep-05 1:48 
GeneralRe: Does it cope with dropdowns lists in IE Pin
Kivanc Ozuolmez28-Sep-05 5:45
memberKivanc Ozuolmez28-Sep-05 5:45 
QuestionRe: Does it cope with dropdowns lists in IE Pin
leo_fulong12-Sep-06 15:53
memberleo_fulong12-Sep-06 15:53 
GeneralGreat!!! Pin
Mesut Koşucu19-Sep-05 22:23
memberMesut Koşucu19-Sep-05 22:23 
GeneralThanx a lot Pin
Eyüp19-Sep-05 21:31
memberEyüp19-Sep-05 21:31 
QuestionServer-side? Pin
Carl Mercier19-Sep-05 7:45
memberCarl Mercier19-Sep-05 7:45 
AnswerRe: Server-side? Pin
Michael J. Collins27-Sep-05 5:11
memberMichael J. Collins27-Sep-05 5:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 19 Sep 2005
Article Copyright 2005 by Kivanc Ozuolmez
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid