beachboy1976
August 27th, 2007, 03:02 PM
Hi,
I tried to use the following code to render a simple textbox to word file. I added a textbox and a button onto my form. However, I got a very strange error. Please help me out with this issue. (I am developing this in ASP.NEt 2.0 and C#)
Here is my code:
ASPX:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML runat="server">
<HEAD runat="server">
<title>DataGridExport</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</form>
</body>
</HTML>
Code Behind:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.Word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
TextBox2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
Error I am getting:
Control 'TextBox2' of type 'TextBox' must be placed inside a form tag with runat=server.
I tried to use the following code to render a simple textbox to word file. I added a textbox and a button onto my form. However, I got a very strange error. Please help me out with this issue. (I am developing this in ASP.NEt 2.0 and C#)
Here is my code:
ASPX:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML runat="server">
<HEAD runat="server">
<title>DataGridExport</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button" OnClick="Button1_Click"></asp:Button>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</form>
</body>
</HTML>
Code Behind:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.Word";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
TextBox2.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
Error I am getting:
Control 'TextBox2' of type 'TextBox' must be placed inside a form tag with runat=server.