Radwindow won't open from code behind

3 posts, 0 answers
  1. Jet
    Jet avatar
    6 posts
    Member since:
    Dec 2010

    Posted 21 Apr 2011 Link to this post

    Hello!
    I know that this is an odd question, but i had been searching the forums with no luck. Something really weird is happening in my web app. i have a form with several controls (comboboxes, labels, textboxes, buttons, a radgrid, a radpanel and a radwindow. All third party controls are from Telerik) to keep some sort of order i have them grouped inside divs (divLeftMenu, divMain, divDetails, divGrid and divbuttons)   all this inside an ajax panel.
    I use to open the radwindow from code behind because most of the time i need to perform server side operations right before open the radwindow. 
    The other form (the buggy one) keeps the same structure, and here comes the weird part. None of my javascript functions run from code behind. not even a simple alert window. Needless to say i can't open my radwindow. 
    The working form:
    In the working form i had to place the radwindow out of the ajaxpanel and place all the other controls inside that panel.
    The code behind that trigger the javascript function is in the RadPanelBar itemclick event. where i set the page that the radwindow will display. To open the radwindow i use the following
    Protected Sub mnuLifts_ItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadPanelBarEventArgs) Handles mnuLifts.ItemClick
            Dim intDay As Integer = Date.Today.Day - 1
            Dim strURL As String = String.Empty
     
            AllParams = New clsParameters
             
            With AllParams
                .CustomerID = Me.cboCustomer.SelectedValue
                .CustomerName = Me.cboCustomer.Text
     
                Select Case  Cint(e.Item.Value)
                    Case  1
                        .qryBase = "uspStoredProc1"
                        .BDate = CDate(Today.Date)
                        .Edate = CDate(Today.Date)
                        strURL = "xxxxxxxx.aspx"
                        AllParams.Title = Me.cboCustomer.Text & "text here ommited"
                    Case 2
                        .qryBase = "uspStoredProc2"
                        AllParams.BDate = String.Empty
                        AllParams.Edate = String.Empty
                        strURL = "yyyyyyyyyy.aspx"
                        AllParams.Title = Me.cboCustomer.Text & "text here ommited"
                    Case "3" ' lifts per month
                        .qryBase = "uspStoredProc3"
                        AllParams.BDate = CDate(DateAdd(DateInterval.Day, -intDay, Today.Date))
                        AllParams.Edate = CDate(Today.Date)
                        strURL = "zzzzzz.aspx"
                        AllParams.Title = Me.cboCustomer.Text & ControlChars.CrLf & "text here ommited " & AllParams.BDate.ToString & " to " & AllParams.Edate.ToString
                   End Select
            End With
            ScriptManager.RegisterStartupScript(Me.Page, Page.GetType(), "radWin", "MyFunction(); return false", True)
            
        End Sub
    The JS Function
    <script type="text/javascript">
     
           function OpenCommun() {
     
               var wnd = $find("<%=dlgCommun.ClientID%>");
               wnd.setUrl("xxxxxxxxxxxxxx.aspx");
               wnd.show();
           }
     
           function GetRadWindow() {
               var oWindow = null;
               if (window.radWindow) oWindow = window.radWindow;
               else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
               return oWindow;
           }
     
           function CloseCommun() {
               GetRadWindow().close();
           }
           
       </script>

    The buggy form:
    Nothing happens if i do as above. the radwindow wont open.
    To make it work manually (i mean by manually open the radwindow with a button and the OnClientClick) i have to place everything inside the ajaxpanel. 
    I have tried radscriptblock, radwindows manager, Me.Page.ClientScript.RegisterStartupScript, ScriptManager.RegisterStartupScript, place the radpanel inside and outside of ajaxpanel, place the radwindow inside and outside. Add simple js functions to test if the problem is just with the js functions related to the radwindow or all of them.
    Weird behaviour 1.
    If i try to test for the script registration in the load event, the whole form freezes, comboboxes doesn't open, textboxes become readonly.
    Weird behaviour 2.
    Implementing the radscriptblock control run once, freezing the form and displaying the script text in the middle of the page.
    To sum up: 
    trying several different ways and i still can't do something as trivial as open a radwindow in an ajaxifixied form. 
    Please if anyone can shade some light on this, will be so much appreciated.
    Thanks!
  2. Cori
    Cori avatar
    562 posts
    Member since:
    Jul 2010

    Posted 25 Apr 2011 Link to this post

    Hello Jet,

    In you RegisterStartupScript call, MyFunction(); return false, there is no need for the "return false" part, since it will get rendered like so in your page:

    <script type="text/javascript">
        MyFunction(); return false
    </script>

     

    Also, since the RadWindow is an ajax control, you need to call your method like so: "Sys.Application.add_load(MyFunction)". The reason being is that the RadWindow object has not been created yet and you need to call your method after it's loaded.

    You could also you the RadAjaxPanel's ResponseScripts to call your method.

    I hope that helps.

  3. Jakub
    Jakub avatar
    3 posts
    Member since:
    Apr 2012

    Posted 15 Apr 2012 Link to this post

    Hello.

    Agree with Cori. Be carfull when dealing with add_load. Load event handlers survives partial postback and it is quite easy to register identical event handler more than once. To avoid such duplication the event handler has to be removed as soon as it is executed:

    (function () {
        var fn = function () {
            MyFunction();
            Sys.Application.remove_load(fn);
        };
        Sys.Application.add_load(fn);
    })();

    More details on this topic.
Back to Top