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

RadWindow Appears Strangely

1 Answer 72 Views
Window
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 14 Feb 2011, 10:37 PM
I am trying to open my radwindow from client-side but this window opens when I set my linkbutton onclientclick event handler, window is opening fine. But when I try to open my radwindow from server-side I can't see my radwindow. Any help would be really appreciable. I don't want to set VisibleOnPageLoad=true because I have multiple radwindows and if any button clicks all window will appear in the screen.

        <asp:LinkButton ID="lbAddCustomer" runat="server" >
        </asp:LinkButton>

 function showWindow() {


                var oWindowCust = $find('<%= rwCustomer.ClientID %>');                
                oWindowCust.show();


                
            }  



<telerik:RadWindow ID="rwCustomer" runat="server" Title="Add Customer" VisibleStatusbar="false" OffsetElementID="lbAddCustomer" 
            Behaviors="Move,Pin,Resize" InitialBehaviors="Pin" VisibleOnPageLoad="false" Height="500" Width="510" Left="150px" 
            
            DestroyOnClose="true">
            <%--        <Shortcuts>
            <telerik:WindowShortcut CommandName="Hide" Shortcut="Esc" />
        </Shortcuts>--%>
            <ContentTemplate>
                <%--<div id="Add Customer" style="text-align: center">--%>
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td align="left" width="30%">
                            <asp:Button ID="btnCustomerCloseWindow" runat="server" Text="Close Window" CausesValidation="False" OnClientClick="return CloseCustomerWindow();"  />
                            &nbsp;
                        </td>
                        <td id="tdbtnImportCustomer" runat="server" >
                            <asp:Button ID="btnImportCustomer" runat="server" Text="Import Customer from Stock System"
                                CausesValidation="false" />
                        </td>
                        <td id="tdbtnAddCustomer" runat="server">
                            <asp:Button ID="btnAddCustomer" runat="server" Text="Add Customer" CausesValidation="false" />
                        </td>
                    </tr>
                </table>



</ContentTemplate>
        </telerik:RadWindow>

Protected Sub lbAddCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbAddCustomer.Click

Page.ClientScript.RegisterStartupScript(Me.GetType(), "key", "<script type='text/javascript'>showWindow();</script>", False)

End Sub

1 Answer, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 17 Feb 2011, 12:15 PM
Hello Muhammad,

 
The controls in the RadControls for ASP.NET AJAX suite are built upon the MS AJAX framework and the framework itself creates its controls (including RadWindow) in the Sys.Application.add_init() method.

Here is how the client events are fired in the page life cycle:

window.onload -> Sys.Application.init -> Sys.Application.load

You can see that the client object representation of MS AJAX controls are created just as the last code on the page in the Sys.Application.init event, which is raised after the window.onload event.

That is why when you call your code in window.onload by registering the client script, the RadWindow will still not be created on the page and you will get an error. To avoid this problem, you can either execute your code with a small timeout, or use the Sys.Application.add_load method.

You can find additional information about this here:

http://blogs.telerik.com/blogs/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx

This being said, you should modify your code e.g in the following manner:

Protected Sub lbAddCustomer_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbAddCustomer.Click
      Page.ClientScript.RegisterStartupScript(Me.GetType(), "key", "Sys.Application.add_load(showWindow);", True
        
      End Sub
<script type="text/javascript">
    function showWindow() {
        Sys.Application.remove_load(showWindow);
        var oWindowCust = $find('<%= rwCustomer.ClientID %>');
        oWindowCust.show();
    }  
</script>

I hope that the provided explanation and resource are helpful and I modified and attached your page, let me know how it goes.

Greetings,
Svetlina
the Telerik team
Tags
Window
Asked by
Muhammad
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Share this question
or