This is a migrated thread and some comments may be shown as answers.

Tooltip as a user message

5 Answers 88 Views
ToolTip
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 28 Apr 2009, 05:27 PM

I have created a user control that uses a tooltip to display a message to the user (success, error and exception messages).

ctlClientMessage.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ctlClientMessage.ascx.cs"   
Inherits="KHSUserControls.ctlClientMessage" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
    <telerik:RadToolTip ID="ClientSideMessageTip" runat="server" RelativeTo="BrowserWindow" Position="BottomRight"   
    VisibleOnPageLoad="true" Animation="Fade" Width="300px" Height="120px" OffsetX="0" OffsetY="0" ShowCallout="false" 
    Skin="Black">  
        <div style="text-align:center; vertical-align: middle;">  
            <div> 
                <h4> 
                    <asp:Label ID="ClientSideMessage" runat="server" ForeColor="white" Text=""></asp:Label> 
                </h4> 
            </div> 
        </div> 
    </telerik:RadToolTip>         

ctlClientMessage.ascx.cs
using System;  
using System.ComponentModel;  
using System.Drawing;  
 
namespace KHSUserControls  
{  
    public partial class ctlClientMessage : System.Web.UI.UserControl, System.ComponentModel.IComponent  
    {  
        public enum MessageType { Error, Success, Information, Exception } ;  
        private string _clientMessage = "";  
 
        /// <summary>  
        /// Auto close delay in milliseconds.  
        /// </summary>  
        [Bindable(true), Category("Data"), Browsable(true), DescriptionAttribute("Auto close delay in milliseconds."),  
         EditorBrowsable(EditorBrowsableState.Always)]  
 
        public int AutoCloseDelayValue { getset; }  
 
        public ctlClientMessage()  
        {  
            AutoCloseDelayValue = 5000;  
        }  
 
        protected override void OnInit(EventArgs e)  
        {  
            if (AutoCloseDelayValue != 0)  
            ClientSideMessageTip.AutoCloseDelay = AutoCloseDelayValue;  
            _clientMessage = "";  
            ClientSideMessage.Text = "";  
            ClientSideMessageTip.VisibleOnPageLoad = false;  
        }  
 
        /// <summary>  
        /// Show client side message. If method is called twice, show the first message unless the new message is an exception.  
        /// </summary>  
        /// <param name="msgType"></param>  
        /// <param name="autoHide"></param>  
        /// <param name="message"></param>  
        public void ShowPageMessage(MessageType msgType, bool autoHide, string message)  
        {  
            if ((_clientMessage == "") || (MessageType.Exception == msgType))  
            {  
                switch (msgType)  
                {  
                    case MessageType.Error:  
                    case MessageType.Exception:  
                        ClientSideMessage.ForeColor = Color.Red;  
                        break;  
                    case MessageType.Success:  
                        ClientSideMessage.ForeColor = Color.Green;  
                        break;  
                    case MessageType.Information:  
                        ClientSideMessage.ForeColor = Color.White;  
                        break;  
                }  
                ClientSideMessageTip.VisibleOnPageLoad = true;  
                _clientMessage = message;  
                ClientSideMessage.Text = _clientMessage;  
                ClientSideMessageTip.ManualClose = !autoHide;  
            }  
            else 
            {  
                return;  
            }  
        }  
    }  

Usage in page.aspx
.  
.  
.  
            </div>  
        </div>                  
    </div>      
        <uc1:ctlClientMessage ID="ClientMessage" runat="server"/>       
    </telerik:RadAjaxPanel>  
.  
.  

page.aspx.cs
        protected void Next_Click(object sender, EventArgs e)  
        {  
            if (NextClaim())  
            {  
                UpdateClaimCount();  
                ClientMessage.ShowPageMessage(ctlClientMessage.MessageType.Information, true"Next record.");  
            }  
            else 
                ClientMessage.ShowPageMessage(ctlClientMessage.MessageType.Information, true"Last record reached.");  
        }  
 


Now the problem is, I am using an ajaxpanel in the page.aspx with the tooltip user control. When I go to this page, I display a message using the tooltip user control but, when I do a postback (Caused by a combobox loading data) the same tooltip message is displayed on the page again. I only want to show the message when I call ClientMessage.ShowPageMessage procedure.


Any ideas?

5 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 01 May 2009, 12:16 PM
Hello David,

Thank you for the provided code, I examined it and replicated the logic in a test demo - after that I reproduced the described problem.

In order to get the desired result, you should not use the VisibleOnPageLoad property but the server method Show() of the tooltip. This being said, please remove the VisibleOnPageLoad="true" from the user control markup and also from the code behind and modify your server code in the following manner:

 protected override void OnInit(EventArgs e)     
26         {     
27             if (AutoCloseDelayValue != 0)     
28             ClientSideMessageTip.AutoCloseDelay = AutoCloseDelayValue;     
29             _clientMessage = "";     
30             ClientSideMessage.Text = "";     
31               
32         }     
33     
34         /// <summary>     
35         /// Show client side message. If method is called twice, show the first message unless the new message is an exception.     
36         /// </summary>     
37         /// <param name="msgType"></param>     
38         /// <param name="autoHide"></param>     
39         /// <param name="message"></param>     
40         public void ShowPageMessage(MessageType msgType, bool autoHide, string message)     
41         {     
42             if ((_clientMessage == "") || (MessageType.Exception == msgType))     
43             {     
44                 switch (msgType)     
45                 {     
46                     case MessageType.Error:     
47                     case MessageType.Exception:     
48                         ClientSideMessage.ForeColor = Color.Red;     
49                         break;     
50                     case MessageType.Success:     
51                         ClientSideMessage.ForeColor = Color.Green;     
52                         break;     
53                     case MessageType.Information:     
54                         ClientSideMessage.ForeColor = Color.White;     
55                         break;     
56                 }     
57                 ClientSideMessageTip.Show();     
58                 _clientMessage = message;     
59                 ClientSideMessage.Text = _clientMessage;     
60                 ClientSideMessageTip.ManualClose = !autoHide;     
61             }     
62             else    
63             {     
64                 return;     
65             }     
66         }     
 

After I did this change, everything started working as expected.

Greetings,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
David
Top achievements
Rank 1
answered on 01 May 2009, 05:04 PM
Hi Svetlina,

I made your modifications but the tooltip still shows up. I think it might be showing up because the javascript that gets embedded in the page to show the tooltip, runs everytime and doesn't get cleared (refreshed).

To further test this, I added ClientSideMessageTip.Show() in the OnInit procedure in the user control code behind which as a result should have showed me a blank tooltip when I do a postback without a call to the ShowPageMessage() procedure, but it doesn't, it shows me the previous message in the tooltip.

        protected override void OnInit(EventArgs e)  
        {  
            if (AutoCloseDelayValue != 0)  
            ClientSideMessageTip.AutoCloseDelay = AutoCloseDelayValue;  
            _clientMessage = "";  
            ClientSideMessage.Text = "";  
            ClientSideMessageTip.Show();  
        } 

The action on the page that is doing the postback (and not calling ShowPageMessage) in the ajaxpanel is:
<telerik:RadComboBox ID="Department" runat="server" EnableEmbeddedSkins="false" Skin="KHS" width="160px" 
                     TabIndex="4" OnSelectedIndexChanged="Department_SelectedIndexChanged" AutoPostBack="true">  
</telerik:RadComboBox>  

When I do a complete refresh of the page (using the test code above) I get the blank tooltip.

I hope this made sense, let me know otherwise=)

Thanks,
Dave
0
Svetlina Anati
Telerik team
answered on 04 May 2009, 01:08 PM
Hello David,

Would you please make sure that you have removed the VisibleOnPageLoad = "true" from the markup of the user control, too? In case you haven't  most probably there are some differences between you project and my test demo and I will really need to examine your code. If so, please prepare a sample reproduction demo, open a new support ticket and send it to me along with detailed reproduction instructions and explanations and I will investigate the issue further and help you achieve the desired behavior.

Greetings,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
David
Top achievements
Rank 1
answered on 04 May 2009, 05:47 PM
Hi Svetlina,

I updated the version of my controls to 2008.3.1314.20 and everything worked perfect. I should have updated before submitting the last message.

The intial solution plus the control udpate helped.

Thank you,
Dave
0
Svetlina Anati
Telerik team
answered on 05 May 2009, 01:58 PM
Hello David,

I am glad that the problem is solved and I would recommend to always provide the exact version of RadControls you are using in order to let us provide you with a faster and better support. In case you experience any further problems, do not hesitate to contact us again.

Regards,
Svetlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ToolTip
Asked by
David
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
David
Top achievements
Rank 1
Share this question
or