Geeks With Blogs

News

Microsoft MVP


Moderator at CodeASP.NET


Quiz Master




free counters
Free counters
Added on January 19,2012


Follow Me @vmsdurano

A bit About Me



Disclaimer
The opinions expressed herein are my own personal opinions and does not represent the opinions of my employers. Nor does it represent the opinion of my dog, because I don’t have one.


Vinz' Blog (ProudMonkey) "Code, Beer and Music ~ my way of being a programmer"

Few days ago I wrote a simple demo about “Using ProudMonkey Controls with ASP.NET AJAX Update Panel”. One small problem is that if for some reasons you will place the MessageBox control outside UpdatePanel then you’ll notice that the MessageBox will not display properly in the page.

So if you were setting your html mark-up like this:

<%@ Register Assembly="AjaxControlToolkit" 
             Namespace="AjaxControlToolkit" 
             TagPrefix="asp" %>
<%@ Register Assembly="ProudMonkey.Common.Controls"
             Namespace="ProudMonkey.Common.Controls"
             Tagprefix="cc1" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <cc1:MessageBox ID="MessageBox1" runat="server"  />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server"
                            onclick="Button1_Click"
                             Text="Show Message" />
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

 

And calling the MessageBox at Button click event:

protected void Button1_Click(object sender, EventArgs e){
      MessageBox1.ShowError("Test ERROR Message!");
} 

 

You will end up getting something like this in the page:

 

m1

 

The reason why it happened because when you do a PostBack some of the attributes defined within MessageBox will not be loaded properly (e.g the src and style). To resolved the issue we can set up Triggers in the UpdatePanel to do postback. Here’s the sample demo below for your reference:

ASPX:

<%@ Register Assembly="AjaxControlToolkit"
             Namespace="AjaxControlToolkit" 
             TagPrefix="asp" %>
<%@ Register Assembly="ProudMonkey.Common.Controls"
             Namespace="ProudMonkey.Common.Controls"
             Tagprefix="cc1" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" >
        </asp:ToolkitScriptManager>
        <cc1:MessageBox ID="MessageBox1" runat="server"  />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Button ID="Button1" runat="server"
                            onclick="Button1_Click"
                            Text="Show Message" />
            </ContentTemplate>
           <Triggers>
                <asp:PostBackTrigger ControlID="Button1" />
            </Triggers>
        </asp:UpdatePanel> 
    </form>
</body>
</html>

Code Behind:

protected void Button1_Click(object sender, EventArgs e){
     MessageBox1.ShowError("Test ERROR Message!");
}  

 

Running the page will display the MessageBox properly. Here’s a sample screen shot below:

m2

That’s it! I hope someone find this post useful.

Posted on Thursday, January 12, 2012 8:24 PM ASP.NET , ProudMonkey Controls | Back to top


Comments on this post: Using MessageBox Control Outside UpdatePanel Control

# re: Using MessageBox Control Outside UpdatePanel Control
Requesting Gravatar...
Thanks that is useful.
Although to resolved the issue we can set up Triggers in the UpdatePanel to do postback.
Left by pari turf on Sep 03, 2012 3:55 AM

comments powered by Disqus

Copyright © Vincent Maverick Durano | Powered by: GeeksWithBlogs.net | Join free