Postback for Button inside RadAjaxPanel

6 posts, 0 answers
  1. Chandan Dey
    Chandan Dey avatar
    50 posts
    Member since:
    Aug 2012

    Posted 04 Aug 2010 Link to this post

    Hi,

     am using old Rad control. "RadAjax.Net2" of "Telerik.WebControls"

    i have a button inside RadAjaxPanel to download a text file from server.

    ASPX Code :
    <%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %>
    <radA:RadAjaxPanel ID="RadAjaxPanel2" runat="server" Width="100%" >
             <table>
                  <tr>
                       <td>
                            <asp:Button ID="btnBillingFile" runat="server"  Text="Generate billing file"   OnClick="btnBillingFile_Click" />
                       </td>
                  </tr>
             </table>
    </radA:RadAjaxPanel>

    C# Code :
    protected void btnBillingFile_Click(object sender, EventArgs e)
    {
                        string fileTabDelimited = ConfigurationManager.AppSettings["KEY_DOCUMENT_FOLDER"] + @"\Billing Files\BillFile.txt";
                        FileInfo fileInfo = new FileInfo(fileTabDelimited);
                        if (fileInfo.Exists)
                        {
                            Response.Clear();
                            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileTabDelimited);
                            Response.AddHeader("Content-Length", fInfo.Length.ToString());
                            Response.ContentType = "application/octet-stream";

                            Response.WriteFile(fileTabDelimited);
                            //Response.End();
                        }
    }

    but not working. This code can not prompt to Open/Save dialog.

    please help.
    Chandan
  2. Prangadj
    Prangadj avatar
    174 posts
    Member since:
    Jan 2008

    Posted 04 Aug 2010 Link to this post

    Chandan, this is Prangadj here. My believ is Response.WriteFile is not supported with Ajax. Move the button outside the ajax panel or cancel ajax with this code - http://www.telerik.com/help/aspnet/ajax/ajxforcingpostback.html.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chandan Dey
    Chandan Dey avatar
    50 posts
    Member since:
    Aug 2012

    Posted 04 Aug 2010 Link to this post

    Hi Prangadj,

    thanks for your help.

    In my page i am unable to move the button outside the ajax panel.

    cancel ajax with this code - http://www.telerik.com/help/aspnet/ajax/ajxforcingpostback.html  not working.

    Chandan
  5. cleophas
    cleophas avatar
    3 posts
    Member since:
    Jun 2009

    Posted 30 Aug 2010 Link to this post

    I have got a better solution. Add a onclick js function
     to your download button as <asp:Button ID="btnDownloadButton" OnClientClick="btnDownloadButton_OnClick()" runat="server" />

    If you are using RadAjaxPanel
    function btnDownloadButton_OnClick()

        var

     

    panel = $find("<%= RadAjaxPanel1.ClientID %>");

     

        panel.set_enableAJAX(

    false);

     

        setTimeout(

    function() {

     

        panel.set_enableAJAX(

    true);

     


    }

    or if you are using RadAjaxManager
    function onDownloadButtonOClick(sender, args)
    {  

     

        var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');

     

        manager.set_enableAJAX(

    false);

     

        setTimeout(

    function() {

     

        manager.set_enableAJAX(

    true);

     


    }
  6. Chandan Dey
    Chandan Dey avatar
    50 posts
    Member since:
    Aug 2012

    Posted 30 Aug 2010 Link to this post

    hi Cleophas,

    Thanks for your reply.

    I saw your code. In my scenario i need to call code-behind code.

    As per your solution how to call my code-behind code in between
    set_enableAJAX(false); and set_enableAJAX(true);

    thanks,
    Chandan
  7. Rakesh
    Rakesh avatar
    4 posts
    Member since:
    May 2013

    Posted 26 Dec 2013 Link to this post

    Thanks Man . I was frustated Because of that .In my aspx page i was having radajax and in my user control i was having link button .so i have to go to api and download the document. Due to ajax the id gets lost when i pass the value to api for download. 


    In case any one have some issue.Have a look.

     <asp:LinkButton ID="btnAddNew" runat="server" ToolTip="Add Document" OnClick="btnAddNew_Click">
                                            <img id="Img1" style="border: 0px" alt="" src="~/Styles/images/Insert.gif" runat="server" />
                                            Add Document
                                        </asp:LinkButton>&nbsp;
    <telerik:RadButton ID="btnDownload" runat="server" Visible="false" Text="Download" OnClick="btnDownload_Click" OnClientClicking="ButtonClick"></telerik:RadButton>


    <telerik:RadCodeBlock ID="rcbScripts" runat="server">
        <script type="text/javascript">

            function onClientItemClicking(sender, eventArgs) {
                var item = eventArgs.get_item();
                if (item.get_expanded()) {
                    eventArgs.set_cancel(true);
                }
            }

            function onRequestStart(sender, args) {
                if (args.get_eventTarget().indexOf("lnkFileName") >= 0) {
                    args.set_enableAjax(false);
                }
            }

            function ButtonClick(sender, args) {

                var count = $('input:checked').length;
                if (count == 0) {
                    alert("Select at least one File");
                    var shouldCancelPostback = true;
                    args.set_cancel(shouldCancelPostback);
                    return false;
                }
                else {
                    var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');
                    manager.set_enableAJAX(false);
                    setTimeout(function () {
                        manager.set_enableAJAX(true);
                        return true;
                    });
                }

            }

            function validateLink() {
                var manager = $find('<%= RadAjaxManager.GetCurrent(Page).ClientID %>');
                manager.set_enableAJAX(false);
                setTimeout(function () {
                    manager.set_enableAJAX(true);
                    return true;
                });

            }

        </script>

    </telerik:RadCodeBlock>

    So i will be getting ajax control from page and disabling the ajax control for that particular user control.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017