473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Getting HTML of a control

Hi,

I am trying to get the HTML of a button and display it in the textbox
in this case. But I always get this error at runtime :

"Control 'Button1' of type 'Button' must be placed inside a form tag
with runat=server."

As you see, the controls HAVE been placed inside the <form
runat="server"> tags. Please help me with this.
Pls give some code snippets if there some other way of getting HTML of
a control.

Thanks !!
..aspx file:

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="webpart2.aspx.cs" Inherits="webpart2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form runat="server">

<asp:TextBox ID="TextBox1" runat="server" Height="69px"
TextMode="MultiLine" Width="192px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
</form>
</body>
</html>

aspx.cs file :

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.IO;

public partial class webpart2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder SB = new StringBuilder();
StringWriter SW = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
Button1.RenderControl(htmlTW);
TextBox1.Text = SB.ToString();
}
}

Oct 19 '05 #1
0 1336

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mohan | last post by:
Hi All, I am using web browser control in a VB 6.0 client server application to print reports. I am writing the report into a HTML file and displays the report to the user using the code,...
3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
2
by: Gerry Abbott | last post by:
Hi all. Im using abbreviated field names on a form to optimise space, but would like to display for example, the status bar text of the control, onto the form header, when the control has the...
2
by: CDWaddell | last post by:
I have the following cod private void btnUpdate_Click(object sender, System.EventArgs e TextBox tbMembers = new TextBox() tbMembers = (TextBox) dlClubs.FindControl("tbMembers") string...
2
by: Alex | last post by:
Hi all, I'm writing a small web application which searches a database based on a date field, and populates a datagrid control with the results. The datagrid control has selection buttons added...
2
by: Chad | last post by:
In our application, I would like to send out HTML mail. TO do so, I must do something like this: Mail.Body = <raw HTMLTEXT String> Hence, I would like to know how to get the HTML text for Web...
0
by: dipgandhi | last post by:
Hi, I am trying to get the HTML of a button and display it in the textbox in this case. But I always get this error at runtime : "Control 'Button1' of type 'Button' must be placed inside a...
6
by: Samuel Rhodes | last post by:
Hi I am trying to write a code snippet that would display a '?' sign on the top left of a control. I do not want to hard code the positioning of the DIV which will contain that '?'. Is it...
2
by: ITistic | last post by:
In a project I have developed there is one Web User Control which we use on 2 different web forms. In addition to using this control on these web forms we now need to be able to send an email out...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.