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

[Solved] How to Reference Ajax Proxy in Javascript on UserControl

6 Answers 428 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Rational Animal
Top achievements
Rank 1
Rational Animal asked on 05 Nov 2007, 09:33 PM
I have a user control on a content page which has a master page. The master page has the ajax manager on it.

On the user control I have a script manager proxy and an rad ajax proxy.

Everything works fine if I just do auto-post backs but this is sub optimal for lots of reasons to do with the post back behaviour of the Calendar.

So I wanted to javascript it based on the client events of the cliendar.

However, no matter what I do I can't get the ajax manager proxy or anything else that allows me to call the AjaxRequestWithTarget and pass the control in question and have it work.

The proxy has the definition for the control that I want to reference etc.

What I"m trying to do is have it work the same way it works with post backs. That is when the calendar has a date selected, it will post back with ajax and only update the other control but will also call the SelectedDateChanged event on the server side.

If the calendar didn't post back when using the navigation buttons I would never have run into this, but I'm sure I need to know how to do this for future development.

Thanks!

6 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 06 Nov 2007, 06:24 AM
Hello Rational Animal,

As I already answered in your support ticket, you can use GetCurrent() method to get an instance of the AJAX Manager and call its AjaxRequest or AjaxRequestWithTarget. This is also discussed in the forums here.

Regards,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rational Animal
Top achievements
Rank 1
answered on 06 Nov 2007, 03:30 PM
This does not help. If you read what I wrote more carefully you'll see that I was talking client side in JAVASCRIPT. Not server side.
0
Konstantin Petkov
Telerik team
answered on 08 Nov 2007, 12:34 PM
Hi,

I must admit I should have explained that better.

First of all, I should start that the ManagerProxy is not designed for anything other then design-time support. So it does not have AjaxRequest/AjaxRequestWithTarget client-side functions. Hence, you need the manager from the MasterPage to call its AjaxRequest client-side and implement the necessary logic in AjaxRequest event server-side. To get the reference of the AJAX Manager client-side object, you can use GetCurrent() RadAjaxManager static method.

Find an example from a content page below:

    <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy> 
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
        <script type="text/javascript"
            function AjaxRequestClient() 
            { 
                var manager = $find("<%= RadAjaxManager.GetCurrent(this).ClientID %>"); 
                manager.AjaxRequest(''); 
            } 
        </script> 
    </telerik:RadCodeBlock> 
    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="Button1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="Label1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/> 
    <asp:Label ID="Label1" runat="server"></asp:Label> 
    <input type="button" value="AjaxRequest" onclick="AjaxRequestClient(); return false;" /> 
 

Let us know whether that helps.

All the best,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rational Animal
Top achievements
Rank 1
answered on 08 Nov 2007, 02:58 PM
Well it posts back now, but it never calls the SelectedDateChanged event on the server side.

I can't find anywhere in the documentation where it explains the event property of an ajax setting and I suspect that's where I need to be looking, but I've tried every variation in the "event" property with no dice.

I need to be able to have it raise, with the value selected by the user the Calendar's OnSelectionChanged event from the ajax "AjaxRequestWithTarget" method in javascript.

What am I missing?
0
Konstantin Petkov
Telerik team
answered on 09 Nov 2007, 06:34 AM
Hi Rational Animal,

You can find RadAjax Client-Side API discussed here in RadAjax documentation. However, reading your explanation again and again, I don't think this is achievable. In general, Calendar's SelectedDateChanged server-side event is fired in case a date is selected from the calendar with its AutoPostBack enabled. So you don't have to trigger an AJAX request yourself from the client-event of the Calendar, you just need to set that Calendar as ajaxified and updated control in manager(or manager proxy) settings like this:

    <telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadCalendar1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="Label1" /> 
                    <telerik:AjaxUpdatedControl ControlID="RadCalendar1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManagerProxy> 
 

The label above is added to show you how you can even update other control on SelectedDateChanged event handler:

    protected void RadCalendar1_SelectionChanged(object sender, Telerik.Web.UI.Calendar.SelectedDatesEventArgs e) 
    { 
        if (e.SelectedDates.Count > 0) 
        { 
            Label1.Text = e.SelectedDates[0].Date.ToLongDateString(); 
        } 
    } 

If you still need to perform AJAX request from the client to trigger Calendar's server-side event, please use the support ticket you have opened to send an application using regular postbacks and we will gladly help you ajaxify it.

Kind regards,
Konstantin Petkov
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Rational Animal
Top achievements
Rank 1
answered on 09 Nov 2007, 04:43 PM
I've sort of worked around this, but I agree the way you just showed is the way it SHOULD work. The problem is that the calendar auto-posts back when you click ANYTHING on it, not just a date so it causes all kinds of havoc.

Hence my javascript solution that I worked around with the EventWithTarget after figuring out with your help how to get the rad ajax manager. It's a hack, butit works nicely.
Tags
Ajax
Asked by
Rational Animal
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Rational Animal
Top achievements
Rank 1
Share this question
or