Here is my ASPX Code:
<%# Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" EnableEventValidation="false" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table align="center">
<tr>
<td colspan="3">
<asp:Label ID="Label6" runat="server" Text="Header Text" style="color:Black;"></asp:Label>
</td>
<td colspan="2" align="right">
<asp:Label ID="Label2" runat="server" Text="Invoice Number : " style="color:Black;"></asp:Label>
<asp:Label ID="Label3" runat="server" Text="" style="color:Black;"></asp:Label>
</td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="Label7" runat="server" Text="Address :" style="color:Black;"></asp:Label><br />
</td>
</tr>
<tr>
<td height="30px" colspan="5">
</td>
</tr>
<tr>
<td align="center" width="150px">
<asp:Label ID="Label22" runat="server" Text="Item" style="color:Black;"></asp:Label>
</td>
<td align="center" width="150px">
<asp:Label ID="Label23" runat="server" Text="Quantity" style="color:Black;"></asp:Label>
</td>
<td align="center" width="150px">
<asp:Label ID="Label24" runat="server" Text="Amount" style="color:Black;"></asp:Label>
</td>
<td align="center" width="150px">
<asp:Label ID="Label25" runat="server" Text="Paid Amount" style="color:Black;"></asp:Label>
</td>
<td align="center" width="150px">
<asp:Label ID="Label26" runat="server" Text="Balance Amount" style="color:Black;"></asp:Label>
</td>
</tr>
<tr>
<td colspan="5" height="5px">
</td>
</tr>
<tr>
<td colspan="5" height="30px">
</td>
</tr>
<tr>
<td colspan="3" valign="top" align="left">
</td>
<td colspan="2" align="right" valign="top">
<table>
<tr>
<td>
<asp:Label ID="Label37" runat="server" Text="Total Amount" style="color:Black;"></asp:Label>
</td>
<td>
<asp:Label ID="Label38" runat="server" Text="" style="color:Black;"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label39" runat="server" Text="Paid Amount" style="color:Black;"></asp:Label>
</td>
<td>
<asp:Label ID="Label40" runat="server" Text="" style="color:Black;"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="5" height="20px">
</td>
</tr>
<tr>
<td colspan="5">
<asp:Label ID="Label41" runat="server" Text="Terms & Condition" style="color:Black;"></asp:Label><br />
</td>
</tr>
<tr>
<td colspan="5" align="right">
<asp:Button ID="Button1" runat="server" Text="Send" onclick="Button1_Click" />
</td>
</tr>
</table>
</asp:Content>
and my C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Text;
using System.Drawing;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string attachment = "attachment; filename=" + "abc" + ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter s_tw = new StringWriter();
HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
h_textw.AddStyleAttribute("font-size", "7pt");
h_textw.AddStyleAttribute("color", "Black");
Document doc = new Document();
doc = new Document(PageSize.A4, 5, 5, 15, 5);
FontFactory.GetFont("Verdana", 80, iTextSharp.text.Color.RED);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
StringReader s_tr = new StringReader(s_tw.ToString());
HTMLWorker html_worker = new HTMLWorker(doc);
html_worker.Parse(s_tr);
doc.Close();
Response.Write(doc);
}
}
I want that if i click on Send Button my ASPX Page save on PDF
My ASPX Page is that:
The problem is that when i click on Send button it gives the following error
The document has no pages
I am using Visual Studio 2010 and ASP.Net C#
I solved my issue using this Code
string attachment = "attachment; filename=" + Session["pdf_name"] + ".pdf";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";
StringWriter s_tw = new StringWriter();
HtmlTextWriter h_textw = new HtmlTextWriter(s_tw);
h_textw.AddStyleAttribute("font-size", "8pt");
h_textw.AddStyleAttribute("color", "Black");
Panel1.RenderControl(h_textw);//Name of the Panel
Document doc = new Document();
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
StringReader s_tr = new StringReader(s_tw.ToString());
HTMLWorker html_worker = new HTMLWorker(doc);
html_worker.Parse(s_tr);
doc.Close();
Response.Write(doc);
Thanks for helping me.
Related
I have the following table and I need to downloaded to PDF.
The method downloads to pdf but it does not display the table's border.
Thank you!
protected void Button2_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
Repeater_AK.RenderControl(htmlTextWriter);
StringReader stringReader = new StringReader(stringWriter.ToString());
Document Doc = new Document(PageSize.A4, 160, 160, 20, 20);
HTMLWorker htmlparser = new HTMLWorker(Doc);
PdfWriter.GetInstance(Doc, Response.OutputStream);
Doc.Open();
htmlparser.Parse(stringReader);
Doc.Close();
Response.Write(Doc);
Response.End();
}
HTML
<table cellspacing="0" style="border-style:solid; font-family:Calibri; border-width:thin;" >
<tr style="height: 26.4pt;">
<td align="center" colspan="6"
style="padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_title" runat="server"
Style="font-weight: bold; font-size:7pt; padding-left:5.4pt; padding-right:5.4pt;">ALASKA INSURANCE IDENTIFICATION CARD</asp:Label>
</td>
</tr>
<tr style="height: 8.4pt;">
<td colspan="2"
style="max-width:98.1pt; padding-left:5.4pt; padding-right:5.4pt; padding-bottom:0px;">
<asp:Label ID="lbl_Company_NAIC_Number" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Company NAIC Number"></asp:Label>
</td>
<td style="width:43.2pt; padding-left:5.4px; padding-right:5.4pt; padding-bottom:0px;">
<asp:Label ID="lbl_Commercial" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Commercial"></asp:Label>
</td>
<td style="width:20.7pt; padding-left:5.4pt; padding-right:5.4pt; padding-bottom:0px;">
</td>
<td style="width:38.7pt; padding-left:5.4pt; padding-right:5.4pt; padding-bottom:0px;">
<asp:Label ID="lbl_Personal" runat="server" Style="font-weight:bold; font-size:7pt;" Text="Personal"></asp:Label>
</td>
<td style="width:16.2pt; padding-left:5.4pt; padding-right:5.4pt; padding-bottom:0px;">
</td>
</tr>
<tr valign="top">
<td colspan="2" style="width:108.9pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Company_NAIC_Number_out" runat="server" Style="font-size:5pt;" Text="31089"></asp:Label>
</td>
<td colspan="4"
style="width:162pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_empty2" runat="server"
Style="font-weight:bold; font-size:7pt;" Text=""></asp:Label>
</td>
</tr>
<tr style="height: 21.6pt;" valign="top">
<td colspan="2"
style="width:108.9pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Company_Name_and_Address" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Company Name and Address"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Company_Name_and_Address_out" runat="server" Style="font-size:5pt;" Text="Repwest Insurance Company"></asp:Label>
</td>
<td colspan="4"
style="width:162pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Company_Phone_Number" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Company Phone Number"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Company_Phone_Number_out" runat="server"
Style="font-size:5pt;" Text="1-800-858-0317"></asp:Label>
</td>
</tr>
<tr style="height: 21.6pt;" valign="top">
<td colspan="2"
style="width:108.9pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Policy_Number" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Policy Number"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Policy_Number_out" runat="server"
Style="font-size:5pt;" Text="PolicyPlaceHolder"></asp:Label>
</td>
<td colspan="2"
style="width:85.5pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Effective_Date" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Effective Date"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Effective_Date_out" runat="server"
Style="font-size:5pt;" Text="4/1/2015"></asp:Label>
</td>
<td colspan="2"
style="width:76.5pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Expiration_Date" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Expiration Date"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Expiration_Date_out" runat="server"
Style="font-size:5pt;" Text="3/31/2016"></asp:Label>
</td>
</tr>
<tr style="height: 22.2pt;" valign="top">
<td style="width:50.4pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Year" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Year"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Year_out" runat="server"
Style="font-size:5pt;" Text='<%# Eval("YEAR") %>'></asp:Label>
</td>
<td style="width:58.5pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Make_Model" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Make/Model"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Make_Model_out" runat="server"
Style="font-size:5pt;" Text='<%# Eval("MODEL") %>'></asp:Label>
</td>
<td colspan="4"
style="width:162pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_VIN" runat="server" Style="font-weight:bold; font-size:7pt;"
Text="Vehicle Identification Number"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_VIN_out" runat="server" Style="font-size:5pt;"
Text='<%# Eval("VIN") %>'></asp:Label>
</td>
</tr>
<tr style="height: 37.8pt;" valign="top">
<td colspan="2"
style="width:108.9pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Agency" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Agency/Company Issuing Card"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Agency_out" runat="server"
Style="font-size:5pt;">Company<br />ADDRESS<br />PHOENIX, AZ 85024</asp:Label>
</td>
<td colspan="4"
style="width:162pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Insured_Name" runat="server"
Style="font-weight:bold; font-size:7pt;" Text="Insured Name and Address"></asp:Label>
<p style="margin:0px;">
</p>
<asp:Label ID="lbl_Insured_Name_out" runat="server" Style="font-size:5pt;"><%# Eval("INSURED_NAME") %><br /><%# Eval("INSURED_ADDRESS") %><br /><%# Eval("INSURED_CITY")%>, <%# Eval("INSURED_STATE")%>  <%# Eval("INSURED_ZIPCODE") %></asp:Label>
</td>
</tr>
<tr style="height: 9.6pt;" valign="top">
<td align="center" colspan="6"
style="width:260.1pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_Not_valid" runat="server"
Style="font-weight:bold; font-size:7pt;"
Text="Not valid for more than one year from effective date"></asp:Label>
</td>
</tr>
<tr style="height: 12pt;">
<td align="center" colspan="6"
style="width:260.1pt; padding-left:5.4pt; padding-right:5.4pt;">
<asp:Label ID="lbl_see_importance" runat="server"
Style="font-weight:bold; font-size:7pt;"
Text="See Important notice on reverse side"></asp:Label>
</td>
</tr>
<tr style="height: 13.7pt;">
<td colspan="6"
style="width:260.1pt; padding-left:5.4pt; padding-right:5.4pt;">
</td>
</tr>
</table>
Ultimately your problem is that you are using an obsolete HTML parser, you should actually be getting a warning from your IDE if you're using a recent version of iTextSharp, and unless you have a lot of legacy code, there really isn't a good reason to not be running the most recent version. If you're running the 4.x version because of the license differences I strongly recommend you read the fourth block on this page.
Regardless, HTMLWorker has very limited support for style commands and border is not one of them. If you want to continue using HTMLWorker, read the fifth paragraph here which tells you which attributes you can use. If you want to change the border using HTMLWorker you're only option that I'm aware of is setting it on the HTML tag itself:
<table border="1">
However, if you switch over to XMLWorker your code will work as expected as long as you change your border-width property to an actual unit like 1px:
<table style="border-style:solid; border-width: 1px;">
I need a clarification weather can I save the webpage to stringbuilder or to a string on a button click as a HTML
My HTML page is
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form2" runat="server">
<div onload="disableBackButton();">
<table align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<div style="padding: 5px; cursor: pointer; vertical-align: middle;">
<div style="float: left; font-size:large; color:Blue; width: 358px;">
( Heading) </div>
<div style="float: left; margin-left: 20px;">
</div>
<div style="float: right; vertical-align: middle;">
</div>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="5">
<tr >
<td align="left" valign="top" style="height: 18px">
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#003399" Font-Size="14pt"
Font-Names="Times New Roman" Text="Name"></asp:Label>
</td>
<td style="width: 175px">
<asp:TextBox ID="TextBox1" runat="server" Width="170px" Height="20px"></asp:TextBox>
</td>
<%--<td width="320px">--%>
<td width="250px">
</td>
<td>
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="#003399" Font-Size="14pt"
Font-Names="Times New Roman" Text="Date"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtDate" runat="server" Width="120px" Height="20px"
ReadOnly="True"></asp:TextBox>
</td>
</tr>
</table>
<table>
<tr>
<td align="center" colspan=2 width="780px">
</td>
</tr>
<tr>
<td align="Left" colspan=3 style=" font-size:18Px; font-family:Times New Roman">
data /////
<br />
<br />
data//
<br>
<br />
Please answer every question.
<br />
<br />
</td>
</tr>
<tr >
<td style="height: 20px; width: 550px;" align=center>
<asp:Label ID="Label3" runat="server"
Text="question." Font-Bold="True"
Font-Size="20px" Font-Underline="True" ForeColor="Navy"
Font-Names="Times New Roman"></asp:Label>
</td>
<td style="height: 20px; width: 240px;" align=center colspan="2">
<asp:Label ID="Label4" runat="server"
Text="Click Your Response" Font-Bold="True"
Font-Size="20px" Font-Underline="True" ForeColor="Navy"
Font-Names="Times New Roman"></asp:Label>
</td>
</tr>
<tr>
<td align="Left" style=" font-size:18Px; font-family:Times New Roman" height="45px">
1. hi do you have car
</td>
<td align="center" width="100px" height="35px">
<asp:RadioButton ID="RadioButton1" CssClass="scaledRadioButton" runat="server" GroupName="Question1"
Text="Yes" Font-Size="12px" Height="20px" Width="49px"/>
</td>
<td align="left" width="100px" height="45px">
<asp:RadioButton ID="RadioButton2" runat="server"
GroupName="Question1" Text="No"
Font-Size="12px" CssClass="scaledRadioButton" Height="20px" Width="49px"/>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
in code behind i bind the values from database end in the load
like this
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xmldoc As New XmlDocument
Dim xmldata As String = "<data><rdBx1>True</rdBx1></data>"
Dim stringReader As New StringReader(kioskxml)
xmldoc.Load(stringReader)
stringReader.Dispose()
If (XmlNodeNavigator.InitializeXmlNodeNavigator(xmldata)) Then
Dim Q1 As String = XmlNodeNavigator.RetrieveElementValue("//data/rdBx1")
If (Q1 = "True") Then
RdbtnQ1Yes.Checked = True
Else
RdBtnQ1No.Checked = True
End If
End If
End Sub
now i want to save this data-binded page as html on a button click in data base
thank you
if I understand more or less, must be render method of the page
string GetInnerHtml()
{
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(sw))
{
Page.RenderChildren(htmlWriter);
return sw.ToString();
}
}
}
VB.NET Version
Function GetInnerHtml() As String
Using sw As New IO.StringWriter
Using htmlWriter As New HtmlTextWriter(sw)
Page.RenderChildren(htmlWriter)
Return sw.ToString()
End Using
End Using
End Function
How to use
public partial class _Default : Page
{
protected override void Render(HtmlTextWriter writer)
{
var html = GetInnerHtml();
//Use html string
Response.Write(html);
}
string GetInnerHtml()
{
using (System.IO.StringWriter sw = new System.IO.StringWriter())
{
using (HtmlTextWriter htmlWriter = new HtmlTextWriter(sw))
{
RenderChildren(htmlWriter);
return sw.ToString();
}
}
}
}
using vb.net you can get the front end code of a page / URL to the page using the following code:
Dim sourceString As new StringBuilder
sourceString.Append(CStr(New System.Net.WebClient().DownloadString(Request.PhysicalPath)))
Where Request.PhysicalPath will gives the address of the current viewing page
so I have this code in asp .net
Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 248px;
}
.auto-style2 {
width: 253px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<table style="width:100%;">
<tr>
<td class="auto-style2">
</td>
<td>
<asp:SqlDataSource ID="Artikujt" runat="server" ConnectionString="<%$ ConnectionStrings:ChipString %>" SelectCommand="SELECT * FROM [Artikujt]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" ></asp:TextBox>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:PlaceHolder ID="PlaceHolder2" runat="server"></asp:PlaceHolder>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:PlaceHolder ID="PlaceHolder3" runat="server"></asp:PlaceHolder>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:PlaceHolder ID="PlaceHolder4" runat="server"></asp:PlaceHolder>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:PlaceHolder ID="PlaceHolder5" runat="server"></asp:PlaceHolder>
</td>
<td> </td>
</tr>
<tr>
<td class="auto-style1"> </td>
<td class="auto-style2">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td> </td>
</tr>
</table>
<br />
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
AddItems();
}
}
DropDownList artikulli;
TextBox cmimi;
Label tregoCmimi;
TextBox sasia;
Label cmimiGjithsej;
protected void AddItems()
{
if (!string.IsNullOrEmpty(TextBox1.Text))
{
int a = int.Parse(TextBox1.Text);
for (int j = 1; j <= a; j++)
{
artikulli = new DropDownList();
cmimi = new TextBox();
tregoCmimi = new Label();
sasia = new TextBox();
cmimiGjithsej = new Label();
//artikulli.ID = j.ToString(IDUnik.ToString("N").Substring(31));
artikulli.ID = "artikulli_" + j.ToString();
artikulli.AutoPostBack = true;
cmimi.ID = "cmimi_" + j.ToString();
cmimi.AutoPostBack = true;
tregoCmimi.ID = "tregoCmimi_" + j.ToString();
sasia.ID = "sasia_" + j.ToString();
sasia.AutoPostBack = true;
cmimiGjithsej.ID = "cmimiGjithsej_" + j.ToString();
PlaceHolder1.Controls.Add(artikulli);
PlaceHolder2.Controls.Add(cmimi);
PlaceHolder3.Controls.Add(tregoCmimi);
PlaceHolder4.Controls.Add(sasia);
PlaceHolder5.Controls.Add(cmimiGjithsej);
DataTable listaArtikujt = new DataTable();
using (SqlConnection lidhje = new SqlConnection(ConfigurationManager.ConnectionStrings["ChipString"].ConnectionString))
{
try
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT [Artikulli] FROM [Artikujt]", lidhje);
adapter.Fill(listaArtikujt);
artikulli.DataSource = listaArtikujt;
artikulli.DataTextField = "Artikulli";
artikulli.DataBind();
}
catch (Exception ex)
{
Response.Write("Gabim:" + ex.ToString());
}
}
}
}
}
}
What I want to do is, after PostBack, after I have added number 2 it will show 2 DropDownlist, 2 Textboxes, 2 Labels, 2 Textboxes again and 2 other Labels.
I am trying to do after Post back, after I enter a number in TextBox cmimi = new TextBox(); it will automatically be added in the label below. I am trying to do but no luck.
I hope you understood my explanation.
Thank you. :)
i am creating a website, in asp.net and using C# my problem is i created a asp repeater which is working fine so i added a imagebutton to download the file that the repeater contains, but i cant get it to download that file, hope someone can help me out i have this already, i have tried a couple of ways but could get it to do what i wanted. here is my code.
ASP
<asp:Repeater ID="RepDetailsPost" runat="server" OnItemCommand="Save" >
<HeaderTemplate>
<table style="width:500px" align ="center" cellpadding="0" class="rounded_corners" >
<tr style="background-color:Red; color:White">
<td valign="top" bgcolor="CC0000" >
<b>Post</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#333">
<td>
<table style="background-color:#222; width:500px" class="rounded_corners" >
<table>
<tr>
<td style="font-size:large">
Utilizador:
<asp:Label ID="lblSubject0" runat="server" Text='<%#Eval("nome_utilizador") %>'
Font-Size="small" Font-Bold="true"/>
</td>
</tr>
</table>
</td>
</tr>
<tr style="background-color:#333;Color:White">
<td align="right" >
Criado em:<asp:Label ID="lblDate0" runat="server" Font-Bold="true"
Text='<%#Eval("data") %>'/>
</td>
</tr>
<tr>
<td>
<table style="background-color:#222; width:500px">
<tr>
<td>Anexo:
<asp:Image ImageUrl=<%# string.Format("~/uploads/{0}",Eval("Nome"))%> runat="server" width=500px/>
</td>
</tr>
</table>
<table style="background-color:#222; width:500px">
<tr>
<td>Guardar:
<asp:ImageButton ID="save" ImageUrl=<%# string.Format("~/imagens/icones/save.png")%> runat="server" width=30px CommandName="save"
CommandArgument='<%# Eval("Nome") %>' />
\\\\\\\\\\\\\\\ this is what I tried on top /////////////////
</tr>
</table>
<table style="background-color:#222; width:500px" align=center>
<tr>
<td>Comentário: <br /><asp:Label ID="lblComment0" Font-Size="small" runat="server" Text='<%#Eval("descricao") %>' /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"valign="top" bgcolor="CC0000">
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
C#
protected void Save(Object Sender, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Save")
{
int index = Convert.ToInt32(e.CommandArgument);
string fName = "teste" ;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);
Response.TransmitFile(Server.MapPath("~/uploadsadmin/" + fName));
Response.End();
}
}
Your method name in OnItemCommand = "Dwn" must match the method name in your code-behind. Rename your Save method to Dwn, or change your markup to match the Save method name.
Refactor the code like this:
if(e.CommandName == "Save")
{
int index = Convert.ToInt32(e.CommandArgument);
string fName = row.Cells[2].Text;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + fName);
Response.TransmitFile(Server.MapPath("~/uploadsadmin/" + fName));
Response.End();
}
Put your breakpoint on the conditional (if...) and see if the breakpoint is hit.
I’m currently working on an asp.net page using C#. This page contains a button and once you click you will get a small HTML table with a name of person, cell phone number and email address. What I want to do is in code behind capture this HTML table along with its data in memory stream or other type of streams in order to do some operations. Here's my code
<table id="tb" runat="server">
<tr>
<td> Name </td>
<td> <asp:Label ID="lblName" runat="server" ></asp:Label> </td>
</tr>
<tr>
<td> Phone </td>
<td> <asp:Label ID="lblPhone" runat="server" ></asp:Label> </td>
</tr>
<tr>
<td> Email </td>
<td> <asp:Label ID="lblEmail" runat="server" ></asp:Label> </td>
</tr>
</table>
So please, if anyone could help of how to accomplish this process and I will be so thankful
Well although I don't really understand why do you want to do that, you can do this pretty simply, you have to put id and runat server tag at your table, and you already have that,
and then render this control to string :
markup:
<form id="form1" runat="server">
<table id="tb" runat="server">
<tr>
<td> Name </td>
<td> <asp:Label ID="lblName" runat="server" ></asp:Label> </td>
</tr>
<tr>
<td> Phone </td>
<td> <asp:Label ID="lblPhone" runat="server" ></asp:Label> </td>
</tr>
<tr>
<td> Email </td>
<td> <asp:Label ID="lblEmail" runat="server" ></asp:Label> </td>
</tr>
</table>
<hr />
Rendered table :
<hr />
<asp:Label ID="lblRenderedTable" runat="server"></asp:Label>
<hr />
</form>
code behind:
protected void Page_Load(object sender, EventArgs e)
{
lblName.Text = "User Name";
lblEmail.Text = "user#domain.com";
lblPhone.Text = "555-4214";
StringBuilder sb = new StringBuilder();
StringWriter tw = new StringWriter(sb);
HtmlTextWriter hw = new HtmlTextWriter(tw);
tb.RenderControl(hw);
string tableContents = sb.ToString();
lblRenderedTable.Text = tableContents;
}