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

Radwindow won't open from code behind

2 Answers 180 Views
Window
This is a migrated thread and some comments may be shown as answers.
Jet
Top achievements
Rank 2
Jet asked on 21 Apr 2011, 11:20 PM
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 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 25 Apr 2011, 01:54 PM
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.

0
Jakub
Top achievements
Rank 1
answered on 15 Apr 2012, 10:51 PM
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.
Tags
Window
Asked by
Jet
Top achievements
Rank 2
Answers by
Cori
Top achievements
Rank 2
Jakub
Top achievements
Rank 1
Share this question
or