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

RadWindow - Now you see it. . .

2 Answers 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 25 Jul 2011, 04:52 AM
... now you don't.

I can't believe I am having this problem. I can make the rad window appear via a client side call to open it, but after postback the very same javascript will not open it.

I have created a small test project  to demonstrate the issue. I don't mind if this my own dumb fault, I just need to know why this is happening. :)

The form has a RadWindow inside a RadWindowManager and two buttons.

The first button is a regular html input type button that's 'onclick' calls the showWindow()  JS function.

The 2nd button is an asp:Button that on click postback to its own event handler. This method simply sets a value on the textbox that is in the window, then it registers some javascript that will call the ShowWindow function. It is on this 2nd call the ShowWindow fails to find the Window.

Here is the relevant part of the aspx code.

<head>
    <title>Now you see it...</title>
</head>
<body>
    <form id="form1" runat="server">
      
    <script type="text/javascript" language="javascript">
 
            function showWindow() {
                var win = $find("<%= RadWindow1.ClientID %>");
                alert(win); // Is NULL after post back
                win.show();
                win.center();
            }
 
    </script>  
 
    
   <asp:ScriptManager ID="ScriptManager1" runat="server">
   </asp:ScriptManager>
               
               <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
                <Windows>
                    <telerik:RadWindow ID="RadWindow1" runat="server">
                        <ContentTemplate>
                            <asp:TextBox ID="tbTest" runat="server" />
                        </ContentTemplate>
                    </telerik:RadWindow>
                </Windows>
            </telerik:RadWindowManager>
    
    
           <input type="button" onclick="showWindow()" value="Client Side" />
                 
           <asp:Button ID="btnShowWindow"  runat="server" OnClick="btnShowWindow_Click" Text="Postback"/>
          
    </form>
</body>
</html>

The button event btnShowWindow_Click looks like this.

protected void btnShowWindow_Click(object sender, EventArgs e)
{
    tbTest.Text = "The window will not appear";
    string jScript = "showWindow();";
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", jScript, true);
}

showWindow gets called just fine. However this time  does not work as the window is not found. (the Alert shows NULL)

This has to be simple. What am I missing here?


2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 25 Jul 2011, 06:39 AM
Hello Brad,

Try the following code snippet.Hope this helps.
C#:
protected void btnShowWindow_Click(object sender, EventArgs e)
 {
    string alertscript = "<script language='javascript'>function f(){showWindow('Welcome to RadWindow <b>Prometheus</b>!', 330, 210); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
    Page.ClientScript.RegisterStartupScript(this.GetType(), "", alertscript);
 }

Thanks,
Shinu.
0
Brad
Top achievements
Rank 1
answered on 25 Jul 2011, 06:56 AM
Man that works. But I have no idea what that code is doing?

Any idea why my code did not work?

Time I googled Sys.Application.add_load me thinks.

Thanks Shinu
Tags
General Discussions
Asked by
Brad
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Brad
Top achievements
Rank 1
Share this question
or