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

Open RadWindow Client Side

3 Answers 967 Views
Window
This is a migrated thread and some comments may be shown as answers.
Muhammad
Top achievements
Rank 1
Muhammad asked on 16 Feb 2011, 12:11 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 using Page.ClientScript 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

3 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 16 Feb 2011, 02:09 PM
Hello Muhammad,

Since the RadWindow is an ASP.NET Ajax control and creates a jQuery object in the browser, the control isn't fully loaded when you call the showWindow method. You should change your Page.ClientScript call to something like this:

Page.ClientScript.RegisterStartupScript(Me.GetType(), "key", "Sys.Application.add_load(showWindow);", True)

I hope that helps.
0
Muhammad
Top achievements
Rank 1
answered on 16 Feb 2011, 03:55 PM
I have tried your solution and setting  VisibleOnPageLoad="true" and Visible="false" but I can't see my radwindow :(. Please provide me some other solution.

<telerik:RadWindow ID="rwCustomer" runat="server" Title="Add Customer" VisibleStatusbar="false" 
            Behaviors="Move,Pin,Resize" InitialBehaviors="Pin" VisibleOnPageLoad="true" Height="500" Width="510" Left="150px" Visible="false"  

Page.ClientScript.RegisterStartupScript(Me.GetType(), "key1", "Sys.Application.add_load(function() {showWindow()});", True)
0
Svetlina Anati
Telerik team
answered on 17 Feb 2011, 12:17 PM
Hi Muhammad,

 
As Cori noted, the RadWindow client object is still not created - I already answered your other thread and for your convenience and for others who need more detailed information about the AJAX client lifecycle, I pasted it below:

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.

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