TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Adhikar Patil
NA
481
129.4k
How to Download Panel Data in PDF File Format
Apr 24 2018 6:53 AM
Hello This is My Source Code
<%@ Page Language=
"C#"
AutoEventWireup=
"true"
CodeFile=
"Test.aspx.cs"
Inherits=
"Test"
%>
<%@ Register Assembly=
"AjaxControlToolkit"
Namespace=
"AjaxControlToolkit"
TagPrefix=
"asp"
%>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<html xmlns=
"http://www.w3.org/1999/xhtml"
>
<head id=
"Head1"
runat=
"server"
>
<title>Generate Certificate</title>
<link href=
"https://fonts.googleapis.com/css?family=Varela+Round"
rel=
"stylesheet"
>
<meta name=
"keywords"
content=
""
>
<link href=
"Css/css/font-awesome.css"
rel=
"stylesheet"
>
<link href=
"Css/css/bootstrap.min.css"
rel=
"stylesheet"
>
<link href=
"Css/css/owl.carousel.css"
rel=
"stylesheet"
>
<link href=
"Css/css/owl.theme.css"
rel=
"stylesheet"
>
<link href=
"Css/css/style.default.css"
rel=
"stylesheet"
>
<link href=
"Css/css/custom.css"
rel=
"stylesheet"
>
<link href=
"Css/css/animate.css"
rel=
"stylesheet"
>
<link rel=
"shortcut icon"
href=
"favicon.png"
>
<link href=
"Css/Comman.css"
type=
"text/css"
rel=
"Stylesheet"
/>
<link href=
"Css/Style.css"
type=
"text/css"
rel=
"Stylesheet"
/>
<link href=
"Student/Css/Style.css"
type=
"text/css"
rel=
"Stylesheet"
/>
<script src=
"js/JScript.js"
type=
"text/javascript"
></script>
<script type=
"text/javascript"
>
function
printDiv(divName) {
var
printContents = document.getElementById(
"<%=divPanel.ClientID %>"
).innerHTML;
var
originalContents = document.body.innerHTML;
document.body.innerHTML = printContents;
document.body.f
window.print();
document.body.innerHTML = originalContents;
document.getElementById(
"<%=divPanel.ClientID %>"
).style.font =
"italic 17px Times New Roman"
;
}
</script>
<style type=
"text/css"
>
hr
{
border-top: 1px solid #ccc !important;
}
.panel
{
box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
border: none !important;
}
</style>
</head>
<body>
<form id=
"form1"
runat=
"server"
>
<asp:ScriptManager ID=
"sm"
runat=
"server"
>
</asp:ScriptManager>
<div
class
=
"navbar navbar-default navbar-fixed-top"
role=
"navigation"
id=
"navbar"
>
<div
class
=
"header"
>
<div
class
=
"container"
>
<div
class
=
"col-lg-8 navbar-header"
>
<button type=
"button"
class
=
"navbar-toggle"
data-toggle=
"collapse"
data-target=
".navbar-collapse"
>
<span
class
=
"sr-only"
>Toggle navigation</span> <span
class
=
"icon-bar"
></span><span
class
=
"icon-bar"
></span><span
class
=
"icon-bar"
></span>
</button>
<a href=
"Default.aspx"
>
<h2>
tallyelearning.com</h2>
</a>
</div>
<div
class
=
"col-lg-4 navbar-collapse collapse pull-left"
id=
"navigation"
>
<ul
class
=
"nav navbar-nav navbar-right list-inline"
>
<li
class
=
"active"
><a href=
"Default.aspx"
>Home</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>
<div
class
=
"container margintop70"
>
<asp:Panel ID=
"pnlSignUp"
runat=
"server"
>
<div
class
=
"col-lg-3"
>
</div>
<div
class
=
"col-lg-8 margintop40 margin-bottom20 margintop40 pull-left"
style=
"width: 45%"
>
<div
class
=
"panel"
>
<div
class
=
"panel-body panel-content"
>
<div
class
=
"col-lg-12 margintop20"
>
<h4>
Get Certificate</h4>
<label>
Continue
with
tallyelearning.com</label>
<hr />
</div>
<div
class
=
"fulldiv col-lg-12"
>
<div
class
=
"form-group fulldiv margintop20"
>
<div
class
=
"col-lg-12 noleftpadding"
>
<label>
First Name</label>
<asp:TextBox ID=
"txtFirstName"
runat=
"server"
CssClass=
"form-control"
MaxLength=
"50"
onblur=
"validateFirstName(this,'txtFirstName');"
></asp:TextBox>
</div>
<div
class
=
"col-lg-12 margintop10 noleftpadding"
>
<label>
Last Name</label>
<asp:TextBox ID=
"txtLastName"
runat=
"server"
CssClass=
"form-control"
MaxLength=
"50"
onblur=
"validateLastName(this,'txtLastName');"
></asp:TextBox>
</div>
</div>
<div
class
=
"form-group fulldiv margintop20"
>
<div
class
=
"col-lg-12 margintop10 noleftpadding"
>
<label>
Email Id</label>
<asp:TextBox ID=
"txtEmailId"
runat=
"server"
CssClass=
"form-control"
MaxLength=
"100"
onblur=
"validateEmail(this,'txtEmailId');"
></asp:TextBox>
</div>
<div
class
=
"col-lg-12 margintop10 noleftpadding"
>
<label>
Contact No</label>
<asp:TextBox ID=
"txtContact"
runat=
"server"
CssClass=
"form-control"
MaxLength=
"10"
onblur=
"return ValidateMobNumber('txtContact')"
></asp:TextBox>
</div>
</div>
<div
class
=
"fulldiv pull-left text-center margintop30 margin-bottom20"
>
<asp:LinkButton ID=
"lnkSignUp"
OnClick=
"lnkSignUp_Click"
runat=
"server"
OnClientClick=
"return CheckBlank()"
CssClass=
"btn btn-theme flatbtn"
Width=
"280px"
Height=
"40px"
Font-Size=
"15px"
Style=
"padding-top: 10px"
><i
class
=
"fa fa-file-pdf-o"
></i> Generate Certificate</asp:LinkButton>
</div>
</div>
</div>
</div>
</div>
</asp:Panel>
<div
class
=
"col-lg-12 margintop10"
>
<div
class
=
"col-lg-3"
>
</div>
<div id=
"divPanel"
runat=
"server"
class
=
"col-lg-5"
style="font-family: Times New Roman;
font-style: italic; font-size: 17px">
<asp:Panel ID=
"pnlCertificate"
runat=
"server"
>
<div
class
=
""
>
<div
class
=
"bg-white margintop10 fulldiv"
>
<div
class
=
"text-center"
>
<img src=
"Student/Images/1.jpg"
width=
"100%"
/>
</div>
<div
class
=
"text-center"
>
This certificate is proudly presented to
</div>
<div
class
=
"text-center margin-bottom10"
>
<asp:Label ID=
"lblName"
runat=
"server"
Font-Bold=
"true"
Font-Size=
"22px"
CssClass=
"firebricktext text-capitalize"
></asp:Label>
</div>
<div
class
=
"text-center margin-bottom10 margintop10"
>
Successfully completed
in
<br />
<asp:Label ID=
"lblCourseName"
CssClass=
"text-capitalize"
runat=
"server"
Font-Bold=
"true"
Font-Size=
"22px"
></asp:Label>
</div>
<div
class
=
"text-center margintop10"
>
<span>At Authorized training center</span>
</div>
<div
class
=
"text-center margin-bottom10"
>
<asp:Label ID=
"lblTrainingCenter"
CssClass=
"text-capitalize"
runat=
"server"
Font-Bold=
"true"
></asp:Label>
</div>
<div
class
=
"text-center margin-bottom10 margintop10"
>
<label>
He/She has awarded
this
certificate
for
distinctive<br />
performance
in
this
programme</label>
</div>
<div style=
"margin-top: 30px; margin-bottom: -71px; float: left; width: 100%"
>
<div
class
=
"margin-bottom10 margintop10"
>
<div
class
=
"col-lg-5"
>
Grade :
<asp:Label ID=
"lblGrade"
runat=
"server"
></asp:Label>
</div>
<div
class
=
"col-lg-5 pull-right"
>
Date of Issue :
<asp:Label ID=
"lblDateofIssue"
runat=
"server"
></asp:Label>
</div>
</div>
<div
class
=
"margin-bottom10 margintop10 fulldiv pull-left"
>
<div
class
=
"col-lg-10"
>
Certificate No :
<asp:Label ID=
"lblCertificateNo"
runat=
"server"
Font-Size=
"18px"
></asp:Label>
</div>
<div
class
=
"col-lg-1"
>
</div>
</div>
</div>
<div
class
=
"text-center"
>
<img src=
"Student/Images/21.jpg"
width=
"100%"
/>
</div>
</div>
</div>
</asp:Panel>
</div>
<div
class
=
"col-lg-4"
>
</div>
<div
class
=
"col-lg-12 margintop10"
>
<div
class
=
"col-lg-2"
>
</div>
<div
class
=
"col-lg-7 text-center"
>
<asp:LinkButton ID=
"lnkPrintPDF"
OnClick=
"lnkPrintPDF_Click"
runat=
"server"
CssClass=
"btn btn-theme"
Visible=
"false"
OnClientClick=
"printDiv('divPanel')"
> Print PDF </asp:LinkButton>
</div>
<div
class
=
"col-lg-3"
>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
AND
Here is MY Code Behind On Button Click Event
protected
void
lnkPrintPDF_Click(Object sender, EventArgs e)
{
Response.Clear();
Response.Buffer =
true
;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset =
""
;
string
FileName =
"Tally Certificate"
+ DateTime.Now +
".pdf"
;
StringWriter sw =
new
StringWriter();
HtmlTextWriter hw =
new
HtmlTextWriter(sw);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType =
"application/pdf"
;
Response.AddHeader(
"Content-Disposition"
,
"attachment;filename="
+ FileName);
pnlCertificate.Visible =
true
;
pnlCertificate.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();
}
So in this Button Click I am downlaod the file but when i open that pdf file i am getting error like Adobe Reader Can not open the file because it is either not a supported file type or because the file has been damaged. So, Please anyone tell me the solution.
Reply
Answers (
1
)
About validator
302 Found:Http message .....................................