Question

I am using Telerik RadControls in my project and and have a menu where I have an 'About' button. When I click the 'About' button a window pops up describing the application. The problem is if I refresh the page or navigate to another page then back to the first page the window automatically pops up.

The goal is only have that window pop up when the user clicks the about button.

here is the code I used to get that window:

<!--About Window-->
<telerik:RadWindowManager runat="server" EnableViewState="false" KeepInScreenBounds="true"></telerik:RadWindowManager>
<telerik:RadWindow ID="AboutMenu" Behaviors="Close" Animation="None" runat="server" Width="360px" KeepInScreenBounds="true" Height="360px" Modal="true" VisibleStatusbar="false" Skin="Glow">
<ContentTemplate>
<p style="text-align: center;">Sample Window Information</p>
</ContentTemplate>
</telerik:RadWindow>

Javascript

function OnClientItemClick(sender, eventArgs) {
             if (window.args.get_item().get_text() == "About") {
                 var radwindow = window.$find(window.AboutMenu.ClientID);
                 window.args.set_cancel(true);
             }
         }

.cs

 protected void MainMenu_OnItemClick(object sender, RadMenuEventArgs e)
        {
            if (e.Item.Text == "About")
            {
                AboutMenu.VisibleOnPageLoad = true;
            }
        }

The window works but it loads whenever the page loads and thats where I think the line AboutMenu.VisibleOnPageLoad = true comes into play and is causing the error but when I take out that line it won't display at all.

Was it helpful?

Solution

Instead of using VisibleOnPageLoad try using the following code to open the window on itemclick.

protected void MainMenu_OnItemClick(object sender, RadMenuEventArgs e)
  {
            if (e.Item.Text == "About")
            {
string script = "function f(){$find(\"" + RadWindow1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);"; 
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);  

            }
  }

OTHER TIPS

Or, just use the OnCLientItemClicking event of the menu to open the RadWindow and cancel the postback. But you will need to fix you JS code, because the arguements are in the context of the current function. ALso, the reference to RW may break unless you have made your own array of ClientIDs.

function OnClientItemClicking(sender, eventArgs) {
         if (eventArgs.get_item().get_text() == "About") {
             var radwindow = window.$find(<%=AboutMenu.ClientID%>);
             radwindow.show();
             eventArgs.set_cancel(true);
         }
     }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top