Click here to Skip to main content
Licence 
First Posted 19 Sep 2005
Views 122,222
Bookmarked 101 times

Server Side MessageBox

By | 19 Sep 2005 | Article
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

About the Author

Kivanc Ozuolmez

Software Developer

Netherlands Netherlands

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionMessage Box Pinmemberswami samarth3:15 19 Apr '12  
GeneralMy vote of 5 Pinmembermanoj kumar choubey21:39 7 Feb '12  
QuestionCool Thanks :) Pinmemberdirekt1239:02 30 Jul '11  
GeneralMy vote of 5 Pinmembershoban_gmail7:47 25 Feb '11  
Questiongrey out background??? Pinmembersimpa5:46 20 Apr '10  
AnswerRe: grey out background??? Pinmembersimpa11:10 4 Mar '11  
GeneralCool But.... Pinmembersinister2322:56 18 Jan '10  
GeneralCool But.... Pinmembersinister2322:56 18 Jan '10  
Generalwith Net 3.5 Pinmemberjtorresrios6:00 8 Sep '09  
GeneralWorking Example Pinmembermayurmv5:07 4 Sep '08  
GeneralDoesn't work in FireFox [modified] Pinmemberemanlee3:49 17 Jul '08  
GeneralRe: Doesn't work in FireFox Pinmemberchankl7820:40 27 Jul '08  
GeneralTeşekkür... PinmemberMember 35369995:04 11 Mar '08  
Generalsession ends Pinmemberaapke_leeye0:18 27 Feb '08  
GeneralDont´function Ajax (Atlas) Pinmemberpsuporte6:26 4 Jul '07  
QuestionMoving the MessageBox [modified] Pinmemberageltzer4:54 7 Jun '07  
GeneralProblem with Master pages PinmemberPablopablo0:39 21 Aug '06  
GeneralRe: Problem with Master pages Pinmembersomeone from the earth0:15 8 Dec '06  
QuestionDoes not work properly after publishing the WEB site PinmemberRohan Chandratileka19:59 9 May '06  
AnswerRe: Does not work properly after publishing the WEB site Pinmemberbritneyssssers12:52 7 Sep '06  
Yeeow, i found the reason, the problem are the form layers, you must to put messagebox over the most external layer, if you have your form statements next to bodies statements the most external one of the layers will be all the page, and you will see this bad behavior.
 
try changing the position of your <form> and </form> statements send them to inside the code page, all you can...
 
Keep Learning...Smile | :)
 
ff

Generalproblem in combination with user control Pinmemberhornox2:57 27 Apr '06  
GeneralRun with Master page Pinmemberplumgrand14:48 20 Apr '06  
GeneralRe: Run with Master page Pinmembertheboton3:02 29 May '06  
GeneralRe: Run with Master page Pinmemberprecozzi2:34 14 Aug '06  
GeneralRe: Run with Master page Pinmemberelpguap999911:00 18 Aug '06  

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.

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