Exclude Toolbar button from Ajax Update

5 posts, 0 answers
  1. Albert Shenker
    Albert Shenker avatar
    586 posts
    Member since:
    Mar 2004

    Posted 31 Aug 2009 Link to this post

    I have a toolbar in a user control which is ajaxified using the following declaration:

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

    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 

    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.

  2. Atanas Korchev
    Atanas Korchev avatar
    8462 posts

    Posted 02 Sep 2009 Link to this post

    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
        <telerik:RadAjaxManager runat="server" ClientEvents-OnRequestStart="onRequestStart">
                <telerik:AjaxSetting AjaxControlID="RadToolBar1">
                        <telerik:AjaxUpdatedControl ControlID="RadToolBar1" />
        <telerik:RadToolBar runat="server" ID="RadToolBar1" AutoPostBack="true">
                <telerik:RadToolBarButton Text="Ajax"></telerik:RadToolBarButton>
                <telerik:RadToolBarButton Text="Postback"></telerik:RadToolBarButton>

    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.
  3. Warren
    Warren avatar
    17 posts
    Member since:
    May 2008

    Posted 07 Apr 2010 Link to this post

    Will this work if the toolbar is in a user control and you are using the RadajaxManagerProxy?

  4. Yana
    Yana avatar
    4995 posts

    Posted 08 Apr 2010 Link to this post

    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,
    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.
  5. Rich Coleman
    Rich Coleman avatar
    19 posts
    Member since:
    Jan 2008

    Posted 23 Sep 2010 Link to this post

    This post saved my life!!!
Back to Top