Duplicate PDF file created when button is clicked the 2nd time. - c#

I followed this link here on how to create html table to pdf in asp.net
I followed the sample code and wired it to my button event handler, and when i clicked it, the pdf file is automatically generated in the respective file directory. But when i clicked it for the second time, it says my filename pdf has been used. I checked the file directory and there is indeed a pdf file being generated. How do i stop the duplication of pdf files when i clicked the button the 2nd time. I'm trying to convert my html table data into a pdf format. I'm wondering if i'm following the correct source.
Attempted sample code :
protected void Button1_Click(object sender, EventArgs e)
{
var document = new Document(PageSize.A4, 50, 50, 25, 25);
var output = new FileStream(Server.MapPath("MyFirstTestPDF.pdf"), FileMode.Create);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
var welcomeParagraph = new Paragraph("Hello, World!");
document.Add(welcomeParagraph);
document.Close();
}
My html table in asp.net
<ul id="Report">
Case ID :
<asp:DropDownList ID="DDLCase" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDLCase_SelectedIndexChanged"
AppendDataBoundItems="true" >
<asp:ListItem Value="-1">Select Member Report ID</asp:ListItem>
</asp:DropDownList>
<table style="width: 100%; height: 576px;">
<tr>
<th style="width: 98px; height: 49px;">Full Name :</th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblFullName" runat="server" Text=""></asp:Label>
</td>
<th style="height: 49px; width: 76px">Contact :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblContact" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px">Location :</th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblLocation" runat="server" Text=""></asp:Label>
</td>
<th style="width: 76px">Type of Crime :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblTOC" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px">Picture : </th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblPicture" runat="server" Text=""></asp:Label>
</td>
<th style="width: 76px">Citizen Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblCRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px">AssignTo :</th>
<td style="width: 351px; height: 49px; text-align: left;">
<asp:Label ID="lblAssign" runat="server" Text=""></asp:Label>
</td>
<th style="width: 76px">Police Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblPRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px; height: 100px;">Citizen Report :</th>
<td colspan="4" style="height: 100px" text-align:"left">
<asp:Label ID="lblCR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px; height: 135px;">Police Report :</th>
<td colspan="4" style="height: 135px" text-align: "left">
<asp:Label ID="lblPR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 98px; height: 135px;">Official Report :</th>
<td colspan="4" style="height: 135px" text-align: "left">
<asp:Label ID="lblOR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
</table>

Did you close the document?
// Close the Document - this saves the document contents to the output stream
document.Close();

Related

colspan screwing up css asp.net table

I created a table to organize my items on a page. The page is an edit page for a property.
I used colspan to expand rows and put a textbox within rows and set the textbox wdith to 100%, However, the textbox width still only takes the space of 1 column not 3 columns like I expected here is the code
<table align="left" style="width: 100%; float: left" class="FormFormatTable">
<tr>
<td style="width: 10%; height: 60px">Alert Name</td>
<td colspan="3" style=" ">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_alertName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width: 10%; height: 60px;">Alert</td>
<td style="height: 60px; ">
<asp:DropDownList ID="ddl_AlertTime" runat="server">
<asp:ListItem Value="1">After</asp:ListItem>
<asp:ListItem Value="0">Immediately</asp:ListItem>
</asp:DropDownList>
</td>
<td style="height: 60px; ">
<input id="demo_vertical0" type="number"/></td>
<td style="height: 60px">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>Seconds</asp:ListItem>
<asp:ListItem>Minutes</asp:ListItem>
<asp:ListItem>Hours</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="width: 10%">Severity</td>
<td style=" height: 60px"" >
<asp:DropDownList ID="ddl_Severity" runat="server">
<asp:ListItem Value="1">After</asp:ListItem>
<asp:ListItem Value="0">Immediately</asp:ListItem>
</asp:DropDownList>
</td>
<td style=""> </td>
<td> </td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Receipients</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_Receipients" runat="server"></asp:TextBox>
</td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Subject Title</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_SubjectTitle" runat="server"></asp:TextBox>
</td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Alert Messsage</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_AlertMessage" runat="server"></asp:TextBox>
</td>
</tr>
<tr style="height:60px">
<td style="width: 10%; ">Notification Window</td>
<td style=" ">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_NotificationWindow" runat="server"></asp:TextBox>
</td>
<td style=" "></td>
<td style="height: 60px"></td>
</tr>
<tr style="height:60px">
<td style="width: 10%; ">Notification Frequency</td>
<td style=" ">
<input id="demo_vertical" type="number"/>
</td>
<td style=" "></td>
<td style="height: 60px"></td>
</tr>
<tr style="height:60px">
<td style="width: 10%">Fields to Display in Details</td>
<td colspan="3" style="">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_SubjectTitle3" runat="server"></asp:TextBox>
</td>
</tr>
</table>
css is simple just this
.inputBoxes {
width: 100%;
}
why is this?
a screenshot of my page on my computer
In you HTML
the Alert Name , Receipients ,Subject Title ,Alert Messsage ,Fields to Display in Details TextBoxs take 3 columns .
Notification Window take one columns because you don't set colspan
you must add colspan="3" to your td of notfication
<td colspan="3" style=" ">
<asp:TextBox CssClass="inputBoxes" ID="txtBox_NotificationWindow" runat="server"></asp:TextBox>
</td>
You have an extra quote in the following line (the cell definition that contains your ddl_Severity control).
<td style=" height: 60px"" >
Maybe remove this quote, and see if that fixes it.

Adding horizontal lines in <div>, or splitting <div> horizontally?

My end users have decided they want to split one piece of my GUI up. What I have currently looks like this:
What they want is this:
The code I'm using is (this is just a snippet, containing the important parts that create this part of the layout):
<div style="width:430px;border:1px solid blue;float:left;">
<asp:Panel ID="Panel6" runat="server" Height="135px" Width="410px">
<br />
<table>
<tr>
<td width="133">Claim Reprocess Required:</td>
<td width="30"><asp:DropDownList ID="cboClmReprocReq" runat="server">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList></td>
<td width="130">Claim Reprocess Date:</td>
<td width="98">
<input type="text" id="txtClmReprocDt" class="datepicker" runat="server" style="height: 14px; width: 70px" />
</td>
</tr>
<tr>
<td width="133">Issue Closed:</td>
<td width="30"><asp:DropDownList ID="cboIssueClosed" runat="server"
OnSelectedIndexChanged="cboIssue_closed_onclick" AutoPostBack="True">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList></td>
<td width="130">Issue Resolution Date:</td>
<td width="98">
<input type="text" id="txtIssResDt" runat="server" class="datepicker" style="height: 14px; width: 70px" />
</td>
</tr>
</table>
</asp:Panel>
</div>
<div style="width:440px;border:1px solid blue;margin-left: 440px;">
<asp:Panel ID="Panel5" runat="server" Height="135px" Width="430px">
<table>
<tr>
<td width="138"></td>
<td width="43"></td>
<td width="50"></td>
<td width="20"></td>
<td width="103"></td>
</tr>
<tr>
<td width="138">Impact Report Required:</td>
<td width="43"><asp:DropDownList ID="cboImpctRprReq" runat="server">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList></td>
<td colspan="2" width="120">Date IR Requested:</td>
<td width="103">
<input type="text" id="txtDtIRReq" runat="server" class="datepicker" style="height: 14px; width: 70px" />
</td>
</tr>
<tr>
<td width="138">Date Range of Impact Report:</td>
<td colspan="2" width="120">
<input type="text" id="txtImpRptStDt" runat="server" class="datepicker" style="height: 14px; width: 70px" />
</td>
<td width="20">To:</td>
<td width="103">
<input type="text" id="txtImpRptEnDt" runat="server" class="datepicker" style="height: 14px; width: 70px" />
</td>
</tr>
<tr>
<td width="138"></td>
<td colspan="3">No. Of Claims Impacted:</td>
<td width="103"><asp:textbox id="txtClmsImpacted" runat="server" Width="70px"></asp:textbox></td>
</tr>
</table>
</asp:Panel>
</div>
<p></p>
<div style="border:1px solid blue;">
<asp:Panel ID="Panel7" runat="server" Height="80px" style="margin-left: 19px" Width="860px">
<br />
<table>
<tr>
<td width="200">Gatekeeper Comments:</td>
<td width="700" rowspan = "4"><asp:textbox id="Textbox_Gtkpr_Cmmnts" runat="server"
textmode="MultiLine" rows="3" Width="700px"></asp:textbox></td>
</tr>
</table>
</asp:Panel>
</div>
Everytime I mess with it, I seem to create a new formatting nightmare. I even tried a simple <hr> tag but that didn't work. I'd like to not do it by creating a table around it all if possible.
I doubt this is of any importance, but this is running in C#. However, it's really just an ASP.Net issue.
Anyone got any ideas?
you can use div
http://jsfiddle.net/MKp6f/
<div>
<table>
<tr>
<td width="133">Claim Reprocess Required:</td>
<td width="30"><asp:DropDownList ID="cboClmReprocReq" runat="server">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList></td>
<td width="130">Claim Reprocess Date:</td>
<td width="98">
<input type="text" id="txtClmReprocDt" class="datepicker" runat="server" style="height: 14px; width: 70px" />
</td>
</tr>
</table>
</div>
<div>
<table>
<tr>
<td width="133">Issue Closed:</td>
<td width="30"><asp:DropDownList ID="cboIssueClosed" runat="server"
OnSelectedIndexChanged="cboIssue_closed_onclick" AutoPostBack="True">
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
</asp:DropDownList></td>
<td width="130">Issue Resolution Date:</td>
<td width="98">
<input type="text" id="txtIssResDt" runat="server" class="datepicker" style="height: 14px; width: 70px" />
</td>
</tr>
</table>
</div>
css
div{
border-style:solid;
border-width:5px;
margin: 4px;
}
Couple of options without splitting the tables etc.
Adding another row with a <hr/> between the 2 input rows, should achieve what you are after:
...
<table>
<tr>
...
</tr>
<tr><td colspan="4"><hr /></td></tr> <!-- Added this line here -->
<tr>
...
</tr>
</table>
...
Otherwise a CSS 'fix', with a 1px background creating the line...
HTML
<div class="boxLeft">
<asp:Panel ID="Panel6" runat="server" Height="135px" Width="410px">
<table>
...
</table>
</asp:Panel>
</div>
CSS
.boxLeft {
width:430px;
border:1px solid blue;
float:left;
background: url('path-to-image') repeat-x center center;
}
.boxLeft table > tr:last-child {
margin-top 10px; // or whatever looks right
}

Cover entire row with a single column - width issue

I have repeater & table controls. My table has one column. When I run the code each cell in the row covers around 25% (based on content of cell) of the row & background color also changes for that area only. I want cell to cover the entire row. Following is the code. I set the column width to 100%, however it did not solve the issue. I do not want to hard code the width for cell.
<div style="overflow-y: auto; width: 100%; height: 395px; border: 0px solid #3C454F; background-color: #FFFBE6; border: 0px solid #3C454F;">
<asp:Repeater ID="TestList" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color: aqua; padding-top: 5px">
<td style="width: 100%;">
<%#Container.DataItem%>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: white; padding-top: 5px">
<td style="width: 100%;">
<%#Container.DataItem%>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
Try this one:
<div style="overflow-y: auto; width: 100%; height: 395px; border: 0px solid #3C454F; background-color: #FFFBE6; border: 0px solid #3C454F;">
<asp:Repeater ID="TestList" runat="server">
<HeaderTemplate>
<table style="width:100%;">
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color: aqua; padding-top: 5px">
<td style="width: 100%;">
<%#Container.DataItem%>
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style="background-color: white; padding-top: 5px">
<td style="width: 100%;">
<%#Container.DataItem%>
</td>
</tr>
</AlternatingItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>

How to clear table data when the default value of the dropdownlist is being selected

How do i clear my table data in my webapp whenever i selected a default value that i have inserted into my dropdownlist?
I have a dropdownlist box with 3 options
SelectPoliceReportID (Default Value)
PoliceReportID123 (Database Value)
PoliceReportID456 (Database Value)
When i select the DB values, they will display out individual DB values, however when i select the default value, the previously clicked DB value information will still remain on the table data.
This is my pageload code where the policereportID will be displayed
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
SqlCommand cm = new SqlCommand("Select pr.policereportid from PoliceReport pr, MemberReport mr where pr.memberreportid=mr.memberreportid and mr.caseprogress='completed'", con);
con.Open();
SqlDataReader dr;
dr = cm.ExecuteReader();
while (dr.Read())
{
DDLCase.Items.Add(dr["policereportid"].ToString());
}
dr.Close();
con.Close();
}
In my previous question, I'm only able to clear my data from my gridview by inserting the following codes after my databind
DDLCase.Items.Clear();
DDLCase.DataSource = ds2;
DDLCase.DataTextField = "memberreportid";
DDLCase.DataValueField = "memberreportid";
DDLCase.DataBind();
DDLCase.Items.Insert(0, new ListItem("Select Member Report ID", ""));
DDLCase.SelectedIndex = 0;
Here is my dropdownlist
protected void DDLCase_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = project; Integrated Security = SSPI");
con.Open();
SqlCommand cm = new SqlCommand("Select lro.fullname, lro.contact, mr.typeofcrime, mr.location,mr.crdatetime, pr.policeid, pr.prdatetime, pr.policereport, pr.image1, mr.citizenreport from MemberReport mr, PoliceReport pr, LoginRegisterOthers lro where pr.policereportid = '" + DDLCase.SelectedValue + "' and mr.memberreportid=pr.memberreportid and lro.username=mr.username and mr.caseprogress='completed'", con);
SqlDataReader dr;
dr = cm.ExecuteReader();
if (dr.Read())
{
lblFullName.Text = dr["fullname"].ToString();
lblContact.Text = dr["contact"].ToString();
lblTOC.Text = dr["typeofcrime"].ToString();
lblLocation.Text = dr["location"].ToString();
lblCRDT.Text = dr["crdatetime"].ToString();
lblPicture.Text = dr["image1"].ToString();
lblAssign.Text = dr["policeid"].ToString();
lblPRDT.Text = dr["prdatetime"].ToString();
lblCR.Text = dr["citizenreport"].ToString();
lblPR.Text = dr["policereport"].ToString();
}
con.Close();
}
Source code for my table. i DID NOT use the asp:table. I programatically added the table into the source code.
<table style="width: 100%; height: 576px;">
<tr>
<th style="width: 595px; height: 49px;">Full Name :</th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblFullName" runat="server" Text=""></asp:Label>
</td>
<th style="height: 49px; width: 134px">Contact :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblContact" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px">Location :</th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblLocation" runat="server" Text=""></asp:Label>
</td>
<th style="width: 134px">Type of Crime :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblTOC" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px">Picture : </th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblPicture" runat="server" Text=""></asp:Label>
</td>
<th style="width: 134px">Citizen Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblCRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px">AssignTo :</th>
<td style="width: 533px; height: 49px; text-align: left;">
<asp:Label ID="lblAssign" runat="server" Text=""></asp:Label>
</td>
<th style="width: 134px">Police Report Date & Time :</th>
<td style="width: 185px; height: 49px; text-align: left;">
<asp:Label ID="lblPRDT" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px; height: 100px;">Citizen Report :</th>
<td colspan="4" style="height: 100px" text-align:"left">
<asp:Label ID="lblCR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px; height: 135px;">Police Report :</th>
<td colspan="4" style="height: 135px" text-align: "left">
<asp:Label ID="lblPR" runat="server" Text="" style="display: block; text-align: left;"></asp:Label>
</td>
</tr>
<tr>
<th style="width: 595px; height: 135px;">Official Report :</th>
<td colspan="4" style="height: 135px">
<asp:TextBox ID="tbofficial" runat="server" Height="121px" TextMode="MultiLine" Width="878px" ></asp:TextBox>
<br />
<asp:Label ID="lblmsg" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:Button ID="btnClear" runat="server" Text="Clear" OnClick="btnClear_Click" />
</td>
</tr>
</table>
in DDLCase_SelectedIndexChanged do below
if(DDLCase.SelectedIndex == 0) // this is the default value
{
lblFullName.Text = String.Empty;
lblContact.Text = String.Empty;
// clear all the textboxes
}else
{
// your code
}
Or you can hide the html table if default value selected. But you need to add id and runat="server" tag to your table. After that you can set yourtable.visible =false; by C# code
If you want to clear all label text then use SelectedIndex like
if(DDLCase.SelectedIndex == 0) // default value
{
foreach (Control ctl in this.Controls)
{
if (ctl is Label)
{
ctl.Text = "";
}
}
}
else
{
// code
}
But If you want to Clear DataTable the you have to use
DataTable.Clear();
Method (System.Data) to clear data table.
MSDN

binded value for a control outside a repeater

Just for curiosity can i give a control that is outside a repeater a binneded value
for example :
<asp:Repeater ID="topicRepeater" runat="server">
<ItemTemplate>
<table border="0" id="bodyTable" runat="server" style="width: 100%; height: 100%;">
<tr>
<td align="left" valign="top" style="padding-top: 6px; padding-right: 30px; padding-left: 5px; width: 50px;">
<img src='App_Themes/WebPortalTheme/images/ProfilePicSmall/<%# Eval("ProPic") %>'
style="width: 50px; height: 50px;" />
<div runat="server" id="username" style="padding-left: 8px; color: #002D79;">
<%# Eval("UserName") %></div>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
<telerik:RadTextBox ID="EditedReplyTxt" Text='<%# Eval("msg_text")%>' runat="server" Width="300px" TextMode="MultiLine" Height="100px"></telerik:RadTextBox>
Yes you can, read this example
http://msdn.microsoft.com/fr-fr/library/4hx47hfe(v=vs.80).aspx

Categories

Resources