5,427,303 members and growing! (19,924 online)
Email Password   helpLost your password?
Web Development » User Controls » General     Intermediate

Server Side MessageBox

By Kivanc Ozuolmez

A web (modal) messagebox without popup.
Javascript, C#, HTML, .NET, Windows, NT4, Win2K, WinXP, Win2003, Vista, TabletPC, Embedded, Visual Studio, ASP.NET, Dev

Posted: 19 Sep 2005
Updated: 19 Sep 2005
Views: 64,490
Bookmarked: 67 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
30 votes for this Article.
Popularity: 6.74 Rating: 4.56 out of 5
1 vote, 3.3%
1
1 vote, 3.3%
2
3 votes, 10.0%
3
2 votes, 6.7%
4
23 votes, 76.7%
5

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



Occupation: Software Developer
Location: Netherlands Netherlands

Other popular User Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 39 (Total in Forum: 39) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralDoesn't work in FireFox [modified]memberemanlee4:49 17 Jul '08  
GeneralRe: Doesn't work in FireFoxmemberchankl7821:40 27 Jul '08  
GeneralTeşekkür...memberMember 35369996:04 11 Mar '08  
Generalsession endsmemberaapke_leeye1:18 27 Feb '08  
GeneralDont´function Ajax (Atlas)memberpsuporte7:26 4 Jul '07  
QuestionMoving the MessageBox [modified]memberageltzer5:54 7 Jun '07  
GeneralProblem with Master pagesmemberPablopablo1:39 21 Aug '06  
GeneralRe: Problem with Master pagesmembersomeone from the earth1:15 8 Dec '06  
QuestionDoes not work properly after publishing the WEB sitememberRohan Chandratileka20:59 9 May '06  
AnswerRe: Does not work properly after publishing the WEB sitememberbritneyssssers13:52 7 Sep '06  
Generalproblem in combination with user controlmemberhornox3:57 27 Apr '06  
GeneralRun with Master pagememberplumgrand15:48 20 Apr '06  
GeneralRe: Run with Master pagemembertheboton4:02 29 May '06  
GeneralRe: Run with Master pagememberprecozzi3:34 14 Aug '06  
GeneralRe: Run with Master pagememberelpguap999912:00 18 Aug '06  
GeneralRe: Run with Master pagememberPKoshti3:49 5 Sep '06  
GeneralRe: Run with Master pagememberjolero_19837:34 22 Jun '07  
QuestionRelocation the Message windowmemberrchokler7:24 3 Apr '06  
GeneralDoes not work in contentplaceholdermemberNick Red5 Brown5:00 16 Dec '05  
GeneralRe: Does not work in contentplaceholdermemberjolero_19837:36 22 Jun '07  
GeneralRe: DOES work with contentplaceholdermemberytmu0096:03 27 Jul '07  
GeneralThe Greatest..!memberstilton@cheese.com2:01 25 Oct '05  
GeneralRe: The Greatest..!memberJohn Sibly7:12 7 Apr '06  
GeneralNot Working for mememberRak_i1:26 25 Oct '05  
GeneralRe: Not Working for mememberKivanc Ozuolmez1:33 25 Oct '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 19 Sep 2005
Editor: Smitha Vijayan
Copyright 2005 by Kivanc Ozuolmez
Everything else Copyright © CodeProject, 1999-2008
Web16 | Advertise on the Code Project