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

$find() returns null in response script from ajaxmanager

8 Answers 218 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Fred Wesson
Top achievements
Rank 1
Fred Wesson asked on 20 May 2010, 06:54 PM
I am trying to display a RadWindow after an ajaxrequest using the ajaxmanagers responsescripts.  It works fine if the ajax request originated from an ajaxpanel, but if the request originates from the ajaxmanager (RadAjaxManager.ajaxRequest('parm')), the $find() function always returns null.

Here is the code behind response script.
RadAjaxManager.ResponseScripts.Add(setTimeout(function(){var _window = $find('" + RadWindow.ClientID + "'); _window.show();}, 250)); 

Am I missing something?

8 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 21 May 2010, 01:36 PM
Hi Fred,

Please try using the following:

JS:
<script type="text/javascript">
    function OpenWindow(sender, args) {
  
       var oWnd = $find("<%= RadWindow1.ClientID %>");
        oWnd.show();
    }
  
</script>

C#:

protected void Button1_Click(object sender, EventArgs e)
   {
        
      RadAjaxManager1.ResponseScripts.Add("OpenWindow");
   }



Kind regards,
Maria Ilieva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fred Wesson
Top achievements
Rank 1
answered on 21 May 2010, 01:57 PM
Same result...I think it's a problem with the ajaxmanager since it works fine if the ajax request originates somewhere other than the ajax manager.
0
Maria Ilieva
Telerik team
answered on 21 May 2010, 02:31 PM
Hello Fred,

I tested this scenario locally however was not able to replicate the described error. Could you please open a regular support ticket and send us small runnable application so we could test it locally and further research on the problem.


All the best,
Maria Ilieva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Fred Wesson
Top achievements
Rank 1
answered on 21 May 2010, 04:06 PM
Thank you...I've opened ticket# 312184
0
Stuart Hemming
Top achievements
Rank 2
answered on 25 Jun 2010, 12:58 AM
Fred,

FWIW, I've just encountered a similar error.

The solution, I found, was to make sure that your calling control updates the window control in your ajax settings.

In my case, I have a button that is supposed to open a window that uses a ContentTemplate, which means it can't be in a RadWindowManager.

I was just using this ...
    protected void btnBeginLogin_Click(object sender, EventArgs e) 
    { 
        RadAjaxManager1.ResponseScripts.Add("openWindow();"); 
    } 

to open the window, but was not getting anywhere. The script function, incidentally, looks like this ...
            function openWindow() { 
                var wnd = $find("<%= RadWindow1.ClientID %>"); 
                wnd.show(); 
            } 

All I needed to do was add a new set of AjaxSettings to my AjaxManager ...
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="btnBeginLogin"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadWindow1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 

I'm guessing here, but I wonder if replacing "btnBeginLogin" in the above with the name of your AjaxManager control would fix your problem.

-- 
Stuart. If this answers your question, please don;t forget to use the "Mark as answer" link.


0
Matthew
Top achievements
Rank 1
answered on 05 Aug 2013, 04:33 PM
Stuart: According to this page, it's best to avoid ajaxifying a RadWindow directly.

Was this problem resolved? I've encountered a similar problem.
0
Maria Ilieva
Telerik team
answered on 08 Aug 2013, 10:54 AM
Hi Matthew,

The mentioned rule is valid for cases when you are using RadWindow control with Content Template in it. In this case instead of ajaxifying the whole RadWindow you should ajaxify the controls in the Content Template.
Could you please elaborate what the exact issue you are facing is so that we could further assist?

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Matthew
Top achievements
Rank 1
answered on 08 Aug 2013, 02:16 PM
In my scenario I use a RadListView to dynamically create a RadWindow (using ContentTemplate) for some records in my database. I couldn't do the typical $find('<% RadWindowX.ClientID %>') because they're inside the RadListView template. I couldn't use static IDs on the RadWindows because that breaks them. I set each RadWindow's ID in the code-behind in order to get uniqueness--I had an issue where after a callback/postback the RadWindows would all be ctrl100 or whatever that default is. In the end I resolved the issue by modifying this KB article to find the RadWindow using the ID I knew I was going to give it.

function getRadWindow(id) {
    if(!Telerik.Web.UI.RadWindow) return null;
    var RadWindows = $telerik.radControls.filter(function (elem) {
        return elem instanceof Telerik.Web.UI.RadWindow;
    });
    var rw = RadWindows.filter(function (elem) {
        return elem.get_name() == id;
    });
    if (rw.length != 1) {
        console.log("Windows: " + rw.map(function (elem) { elem.get_name() + ' '; }));
        return null;
    }
    else return rw[0];
}

When I started using this I figured out the RadWindow IDs were getting reset, so that was probably my issue. I must've set the IDs on the initial request, but neglected to set it again on the callbacks/postbacks.
Tags
Ajax
Asked by
Fred Wesson
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Fred Wesson
Top achievements
Rank 1
Stuart Hemming
Top achievements
Rank 2
Matthew
Top achievements
Rank 1
Share this question
or