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

Server Side MessageBox

By , 19 Sep 2005
 

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
No Biography provided

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.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralDoesn't work in FireFox [modified]memberemanlee17 Jul '08 - 3:49 
The background color of Mbox become Black in FF, and there are two pink lines up and down the screen.
 
I updated codes as below:
<table runat="server" id="MainTable" name="MainTable" style="border-width: 0px; border-collapse: collapse; border-color: #EAEBEF; ">
            width="100%" height="100%">
            <tr style="background-color: #EAEBEF; border-width: 0px; border-color: #EAEBEF; border-collapse: collapse;">
                <td style="width: 62px; height: 96px;border-width: 0px;border-color: #EAEBEF; " valign="middle" align="center">
                    <asp:image id="iIcon" runat="server" xmlns:asp="#unknown"></asp:image></td>
                <td style="height: 96px;border-width: 0px;border-color: #EAEBEF; " valign="middle" align="left" colspan="3">
                    <asp:label id="lblMessage" runat="server" width="100%" height="100%" forecolor="#1F336B" xmlns:asp="#unknown">
                        Font-Names="Arial" Font-Size="Smaller"></asp:label></td>
            </tr>
            <tr align="center" style="background-color: #EAEBEF; border-width: 0px; border-color: #EAEBEF;<br mode=" hold=" />                border-collapse: collapse; ">
                <td style="width: 62px; height: 26px;border-width: 0px;border-color: #EAEBEF; ">
                </td>
                <td valign="bottom" align="right" style="height: 26px;border-width: 0px;border-color: #EAEBEF; ">
                    <asp:button id="btn1" runat="server" text="Button" cssclass="button" onclick="btn1_Click" xmlns:asp="#unknown">
                        Width="60px"></asp:button><asp:button id="btn2" runat="server" text="Button" cssclass="button" xmlns:asp="#unknown">
                            OnClick="btn2_Click" Width="60px"></asp:button><asp:button id="btn3" runat="server" xmlns:asp="#unknown">
                                Text="Button" OnClick="btn3_Click" Width="60px"></asp:button></td>
            </tr>
        </table>
 
but the border of the table is still BLACK.
 
modified on Thursday, July 17, 2008 10:24 AM

GeneralRe: Doesn't work in FireFoxmemberchankl7827 Jul '08 - 20:40 
I had tried that solution, my background colour is still black.
Please advice.
 
Smile
chankl78

GeneralTeşekkür...memberMember 353699911 Mar '08 - 5:04 
Tesekkür ederim çok iyi bir çözüm sagladin bana.
Generalsession endsmemberaapke_leeye27 Feb '08 - 0:18 
Great control! but why does the session expires when i use the control on my child page?
GeneralDont´function Ajax (Atlas)memberpsuporte4 Jul '07 - 6:26 
Not show page messagebox
QuestionMoving the MessageBox [modified]memberageltzer7 Jun '07 - 4:54 
Hello,
I used your excellent code of the MessageBox, but I had small problem.
Is there a way to manually change the location of the control?
Basicly, I'm asking the same question as rchokler asked you on 12:24 3 Apr '06
 
Please respond with an answer if you can.
 
Thanks.
 

-- modified at 11:00 Thursday 7th June, 2007
GeneralProblem with Master pagesmemberPablopablo21 Aug '06 - 0:39 
Hi...
 
I use Master pages and try to use the update, wish were posted ealier:
 
gPopupMask = document.getElementById("<%=popupMask.ClientID %>");
 
But it has not changed anything - nothing still happens when run my page...?? Confused | :confused:
GeneralRe: Problem with Master pagesmembersomeone from the earth8 Dec '06 - 0:15 
I changed the code, it works but the msg box does not changed ,, I don't know why ,, it does it response to the buttons click or any thing
 
!!!
QuestionDoes not work properly after publishing the WEB sitememberRohan Chandratileka9 May '06 - 19:59 
Unsure | :~ Great Control!! It works fine in the VS 2005 development environment. However after publishing the WEB site and run from the browser Mbox appearance changes. Entire contentplaceholder becomes Gray color and Mbox popup background changes to black. Do you know the reason for this?
 
Rohan Chandratileka
AnswerRe: Does not work properly after publishing the WEB sitememberbritneyssssers7 Sep '06 - 12:52 
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

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

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