Click here to Skip to main content
Click here to Skip to main content

Server Side MessageBox

By , 19 Sep 2005
Rate this:
Please Sign up or sign in to vote.

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

About the Author

Kivanc Ozuolmez
Software Developer
Netherlands Netherlands
No Biography provided

Comments and Discussions

 
QuestionMessage Box Pinmemberswami samarth19-Apr-12 3:15 
SuggestionRe: Message Box PinmemberWebBHTAN22-Dec-13 4:58 
GeneralMy vote of 5 Pinmembermanoj kumar choubey7-Feb-12 21:39 
QuestionCool Thanks :) Pinmemberdirekt12330-Jul-11 9:02 
AnswerRe: Cool Thanks :) PinmemberWebBHTAN22-Dec-13 4:58 
GeneralMy vote of 5 Pinmembershoban_gmail25-Feb-11 7:47 
Questiongrey out background??? Pinmembersimpa20-Apr-10 5:46 
AnswerRe: grey out background??? Pinmembersimpa4-Mar-11 11:10 
GeneralCool But.... Pinmembersinister2318-Jan-10 22:56 
GeneralCool But.... Pinmembersinister2318-Jan-10 22:56 
Generalwith Net 3.5 Pinmemberjtorresrios8-Sep-09 6:00 
GeneralWorking Example Pinmembermayurmv4-Sep-08 5:07 
GeneralDoesn't work in FireFox [modified] Pinmemberemanlee17-Jul-08 3:49 
GeneralRe: Doesn't work in FireFox Pinmemberchankl7827-Jul-08 20:40 
AnswerSolution: Doesn't work in FireFox PinmemberWebBHTAN22-Dec-13 4:55 
GeneralTeşekkür... PinmemberMember 353699911-Mar-08 5:04 
Generalsession ends Pinmemberaapke_leeye27-Feb-08 0:18 
GeneralDont´function Ajax (Atlas) Pinmemberpsuporte4-Jul-07 6:26 
QuestionMoving the MessageBox [modified] Pinmemberageltzer7-Jun-07 4:54 
GeneralProblem with Master pages PinmemberPablopablo21-Aug-06 0:39 
GeneralRe: Problem with Master pages Pinmembersomeone from the earth8-Dec-06 0:15 
QuestionDoes not work properly after publishing the WEB site PinmemberRohan Chandratileka9-May-06 19:59 
AnswerRe: Does not work properly after publishing the WEB site Pinmemberbritneyssssers7-Sep-06 12:52 
Generalproblem in combination with user control Pinmemberhornox27-Apr-06 2:57 
GeneralRun with Master page Pinmemberplumgrand20-Apr-06 14:48 
GeneralRe: Run with Master page Pinmembertheboton29-May-06 3:02 
GeneralRe: Run with Master page Pinmemberprecozzi14-Aug-06 2:34 
GeneralRe: Run with Master page Pinmemberelpguap999918-Aug-06 11:00 
GeneralRe: Run with Master page PinmemberPKoshti5-Sep-06 2:49 
GeneralRe: Run with Master page Pinmemberjolero_198322-Jun-07 6:34 
QuestionRelocation the Message window Pinmemberrchokler3-Apr-06 6:24 
GeneralDoes not work in contentplaceholder PinmemberNick Red5 Brown16-Dec-05 4:00 
GeneralRe: Does not work in contentplaceholder Pinmemberjolero_198322-Jun-07 6:36 
As this solution doesn't work for me (and i don't know why, cause i do not know javascript) i digged more, what took me over 2 days (i'm new to asp.net though) and i do not really know, why haven't yet anybody posted solution i'm going to give here, because when you'll see it, you certainly will agree with me, that all those mvp's and other great guys had to know it.
 
So to make this great control work in all common *.aspx and in the ones bounded to some ContentPlaceHolder:
- open the behind cs code file
- find the one of the overloaded Show methods that invokes ShowPowWin script
- it gives the script three parameters - third is the ID of the control to show, but ID is the ID of control in the ascx file, but we need ID of the control in the entire page which differs f.e. when mbox is placed in ContentPlaceHolder (you can see this when you open source of page shown in your IE or sth)
- change this.ID to this.ClientID, which is generated on fly by framework when it is generating the page for the request
 
That's all ! I specially made account here, to write this and save some other people hours of searching and frustration - because if i didn't find this solution i would certainly depracete it and never use anymore.
 
Good Luck
GeneralRe: DOES work with contentplaceholder Pinmemberytmu00927-Jul-07 5:03 
GeneralThe Greatest..! Pinmemberstilton@cheese.com25-Oct-05 1:01 
GeneralRe: The Greatest..! PinmemberJohn Sibly7-Apr-06 6:12 
GeneralNot Working for me PinmemberRak_i25-Oct-05 0:26 
GeneralRe: Not Working for me PinmemberKivanc Ozuolmez25-Oct-05 0:33 
GeneralNo Work PinmemberJan Waiz14-Oct-05 4:19 
GeneralRe: No Work PinmemberToasty014-Oct-05 4:49 
QuestionWhat about a live demo or ASP.NET 1.1 version? PinmemberManuDev28-Sep-05 12:41 
GeneralUser CSS PinmemberSean Feldman28-Sep-05 4:49 
GeneralRe: User CSS PinmemberKivanc Ozuolmez28-Sep-05 5:16 
GeneralDoes it cope with dropdowns lists in IE Pinmembertony_bbc28-Sep-05 0:48 
GeneralRe: Does it cope with dropdowns lists in IE PinmemberKivanc Ozuolmez28-Sep-05 4:45 
QuestionRe: Does it cope with dropdowns lists in IE Pinmemberleo_fulong12-Sep-06 14:53 
GeneralGreat!!! PinmemberMesut Koşucu19-Sep-05 21:23 
GeneralThanx a lot PinmemberEyüp19-Sep-05 20:31 
QuestionServer-side? PinmemberCarl Mercier19-Sep-05 6:45 
AnswerRe: Server-side? PinmemberMichael J. Collins27-Sep-05 4: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 | Mobile
Web03 | 2.8.140421.2 | Last Updated 19 Sep 2005
Article Copyright 2005 by Kivanc Ozuolmez
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid