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

Exclude Toolbar button from Ajax Update

4 Answers 103 Views
ToolBar
This is a migrated thread and some comments may be shown as answers.
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Albert Shenker asked on 31 Aug 2009, 06:33 PM
I have a toolbar in a user control which is ajaxified using the following declaration:

<telerik:RadAjaxManagerProxy ID="rap1" runat="server" > 
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="rtbActions">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="pnlFFV" LoadingPanelID="lpFFV" /> 
                <telerik:AjaxUpdatedControl ControlID="rtbActions" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy>  

When certain toolbar buttons are clicked, controls are updated within a panel control (pnlFFV), and sometimes the toolbar itself is updated. This all works well, however, there is a button in the toolbar, which I want to cause a postback instead of an ajax update (this button is used to download a file and it is necessay to use the reponse object). I tried the following:

I added this script:


function realPostBack_FFV(eventTarget, eventArgument) {  
     $find("<%= rap1.ClientID %>").__doPostBack(eventTarget, eventArgument);  

and in codebehind, I tried to wire it up to the particular toolbar button

For Each itm As RadToolBarButton In rtbActions.Items  
     If itm.Value = "Download" Then 
          itm.Attributes.Add("onclick"String.Format("realPostBack_FFV('{0}', ''); return false;", itm.UniqueID))  
     End If 
Next 

However, this button still causes an ajax update. can someone help me figure out how to exclude a particular toolbar button from an ajaxupdate if the rest of the toolbar is ajaxified?

P.S., I also tried modifying the javascript to reference the AjaxManager instead of the Proxy, like so:

function realPostBack_FFV(eventTarget, eventArgument) {     
     $find("<%= Me.MyAjaxManager.ClientID %>").__doPostBack(eventTarget, eventArgument);     
}    
 //Me.MyAjaxManager gets a reference to the shared AjaxManager in my base page class

But this dind't seem to make a difference.


4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Sep 2009, 01:23 PM
Hi Albert Shenker,

Unfortunately it is not that simple. Calling __doPostBack manually will not prevent ajax as the DOM element which triggers the click is within update panel (that's how ASP.NET Ajax determines whether to postback or make ajax).

I suggest the following solution instead:

    <telerik:RadCodeBlock runat="server" ID="RadCodeBlock1">
        <script type="text/javascript">
            function onRequestStart(sender, args) {
                var eventTarget = args.get_eventTarget(); //the UniqueID of the control which triggers the ajax
                var toolBar = $find("<%= RadToolBar1.ClientID %>");
               
                if (eventTarget.replace(/\$/ig,"_") == toolBar.get_id()) { //check if this is the toolbar
                    var index = parseInt(args.get_eventArgument()); //the index of the button which was clicked
                    var button = toolBar.get_items().getItem(index);
                    if (button.get_text() == "Postback") { // cancel the ajax
                        args.set_enableAjax(false);
                    }
                }
            }
        </script>
    </telerik:RadCodeBlock>
   
    <telerik:RadAjaxManager runat="server" ClientEvents-OnRequestStart="onRequestStart">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadToolBar1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadToolBar1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
   
    <telerik:RadToolBar runat="server" ID="RadToolBar1" AutoPostBack="true">
        <Items>
            <telerik:RadToolBarButton Text="Ajax"></telerik:RadToolBarButton>
            <telerik:RadToolBarButton Text="Postback"></telerik:RadToolBarButton>
        </Items>
    </telerik:RadToolBar>

Regards,
Atanas Korchev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Warren
Top achievements
Rank 1
answered on 07 Apr 2010, 09:15 PM
Will this work if the toolbar is in a user control and you are using the RadajaxManagerProxy?


0
Yana
Telerik team
answered on 08 Apr 2010, 01:34 PM
Hello Warren,

RadAjaxManagerProxy doesn't provide the client-side events as RadAjaxManager,  here it's demonstrated how to attach the events to the manager from the user control.

All the best,
Yana
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
Rich Coleman
Top achievements
Rank 1
answered on 23 Sep 2010, 10:40 PM
This post saved my life!!!
Tags
ToolBar
Asked by
Albert Shenker
Top achievements
Rank 1
Veteran
Iron
Answers by
Atanas Korchev
Telerik team
Warren
Top achievements
Rank 1
Yana
Telerik team
Rich Coleman
Top achievements
Rank 1
Share this question
or