Sunday, February 19, 2012

ChangingResponse type at server side on click of button which is in updatepanel

ASPX Code :

< asp:ScriptManager ID="scManager" runat="server">< /asp:ScriptManager>
< asp:UpdatePanel ID="aaa" runat="server" UpdateMode="Conditional">
< ContentTemplate>
< asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Downlaod" />
< /ContentTemplate>
< Triggers>
< /Triggers>
< /asp:UpdatePanel>

Page Load Event :

string strScriptKey = this.ClientID + "_AsposeDownload";
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(strScriptKey))
{
string strScriptBlock = "";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), strScriptKey, strScriptBlock);
}


JS Code :


function blockUIForDownload() {
Download();
}


function Download() {
try {
location.href = "Handler1.ashx";
//finishDownload();
}
catch (err) {
}
return false; // Return false to stop the page posting back
}


Global Handler with the following code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Aspose.Slides.Pptx;

namespace WebApplication1
{
///
/// Summary description for Handler1
///
public class Handler1 : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
PresentationEx pres = new PresentationEx();
SlideEx slide = pres.Slides[0];
slide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 0, 0, 500, 100);
slide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 0, 305, 500, 100);
TextFrameEx tf1 = ((AutoShapeEx)slide.Shapes[0]).TextFrame;
TextFrameEx tf2 = ((AutoShapeEx)slide.Shapes[1]).TextFrame;
for (int i = 0; i < 500; i++)
{
tf1.Text += "\r\rQa will continue &amp; testing for al formatting issue\r\r";
tf2.Text += "";
}
ParagraphEx para1 = tf1.Paragraphs[0];
ParagraphEx para2 = tf2.Paragraphs[0];
para2.BulletType = BulletTypeEx.Numbered;
ParagraphEx para3 = new ParagraphEx();
para3.BulletType = BulletTypeEx.Numbered;
para3.Indent = 144;
para3.Alignment = TextAlignmentEx.Center;
para3.Text = "";
tf2.Paragraphs.Add(para3);
para1.MarginLeft = 72;
para2.Indent = 144;
float Par1Margin = para1.MarginLeft;
string strHttpResCT = "application/vnd.ms-powerpoint";
string strHttpHdrCD = "attachment; filename=PowerPointFile.pptx";
Aspose.Slides.Export.SaveFormat sfOutputFormat = Aspose.Slides.Export.SaveFormat.Pptx;
HttpContext.Current.Response.ContentType = strHttpResCT;
HttpContext.Current.Response.AddHeader("Content-Disposition", strHttpHdrCD);
pres.Save(HttpContext.Current.Response.OutputStream, sfOutputFormat);
HttpContext.Current.Response.Flush();

}

public bool IsReusable
{
get
{
return false;
}
}
}
}

No comments:

Post a Comment