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

Postback for Button inside RadAjaxPanel

5 Answers 413 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chandan Dey
Top achievements
Rank 1
Chandan Dey asked on 04 Aug 2010, 12:08 PM
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

5 Answers, 1 is accepted

Sort by
0
Prangadj
Top achievements
Rank 1
answered on 04 Aug 2010, 12:33 PM
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.

0
Chandan Dey
Top achievements
Rank 1
answered on 04 Aug 2010, 01:29 PM
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
0
cleophas
Top achievements
Rank 1
answered on 30 Aug 2010, 08:56 AM
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);

 


}
0
Chandan Dey
Top achievements
Rank 1
answered on 30 Aug 2010, 12:29 PM
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
0
Rakesh
Top achievements
Rank 1
answered on 26 Dec 2013, 03:00 PM
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.
Tags
General Discussions
Asked by
Chandan Dey
Top achievements
Rank 1
Answers by
Prangadj
Top achievements
Rank 1
Chandan Dey
Top achievements
Rank 1
cleophas
Top achievements
Rank 1
Rakesh
Top achievements
Rank 1
Share this question
or