473,625 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting the Html text for a control...

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 Controls.

You'll notice below in lines 33-37 that that code does correctlt return the HTML for a textbox. How do I make it generic so it returns the HTML for any control. Hopefully, if the control is a container control, it will return the HTML for ALL nested controls, too.

When I hit line 40, I get the error: Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.

Thanks for any comments that may be offered.

Chad

1 Public Class WebForm1
2 Inherits System.Web.UI.P age
3
4 #Region " Web Form Designer Generated Code "
5
6 'This call is required by the Web Form Designer.
7 <System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
8
9 End Sub
10 Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
11
12 'NOTE: The following placeholder declaration is required by the Web Form Designer.
13 'Do not delete or move it.
14 Private designerPlaceho lderDeclaration As System.Object
15
16 Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
17 'CODEGEN: This method call is required by the Web Form Designer
18 'Do not modify it using the code editor.
19 InitializeCompo nent()
20 End Sub
21
22 #End Region
23
24 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
25 'Put user code to initialize the page here
26
27 Dim s As String = GetHtmlForContr ol(Button1)
28
29 End Sub
30 Public Function GetHtmlForContr ol(ByVal Control As System.Web.UI.C ontrol) As String
31
32
33 'Dim Tbx As New TextBox
34 'Tbx.Text = "Hello World!"
35 'Dim Writer As HtmlTextWriter = New HtmlTextWriter( New System.IO.Strin gWriter)
36 'Tbx.RenderCont rol(Writer)
37 'Dim s As String = Writer.InnerWri ter.ToString()
38
39 Dim Writer As System.Web.UI.H tmlTextWriter = New System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)
40 Control.RenderC ontrol(Writer)
41 Dim Htmltext As String = Writer.InnerWri ter.ToString()
42 Return Htmltext
43
44 End Function
45 End Class



Server Error in '/WebApplication1 ' Application.
--------------------------------------------------------------------------------

Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Http Exception: Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.

Source Error:

Line 38:
Line 39: Dim Writer As System.Web.UI.H tmlTextWriter = New System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)
Line 40: Control.RenderC ontrol(Writer)
Line 41: Dim Htmltext As String = Writer.InnerWri ter.ToString()
Line 42: Return Htmltext

Source File: c:\inetpub\wwwr oot\WebApplicat ion1\WebForm1.a spx.vb Line: 40
Nov 19 '05 #1
2 2345
Looks like as long as the control is created a run time, I dont have a problem.

Thanks anyways.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

Dim B As New Button

Dim T As New Table

Dim TableRow As New TableRow

T.Rows.Add(Tabl eRow)

Dim C As New TableCell

TableRow.Cells. Add(C)

C.Controls.Add( B)

Dim HTML As String = GetHtmlForContr ol(T)

End Sub

Public Function GetHtmlForContr ol(ByVal Control As System.Web.UI.C ontrol) As String

'Dim Tbx As New TextBox

'Tbx.Text = "Hello World!"

'Dim Writer As HtmlTextWriter = New HtmlTextWriter( New System.IO.Strin gWriter)

'Tbx.RenderCont rol(Writer)

'Dim s As String = Writer.InnerWri ter.ToString()

Dim Writer As System.Web.UI.H tmlTextWriter = New System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)

Control.RenderC ontrol(Writer)

Dim Htmltext As String = Writer.InnerWri ter.ToString()

Return Htmltext

End Function

"Chad" <ch************ **@unisys.com> wrote in message news:dg******** **@trsvr.tr.uni sys.com...
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 Controls.

You'll notice below in lines 33-37 that that code does correctlt return the HTML for a textbox. How do I make it generic so it returns the HTML for any control. Hopefully, if the control is a container control, it will return the HTML for ALL nested controls, too.

When I hit line 40, I get the error: Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.

Thanks for any comments that may be offered.

Chad

1 Public Class WebForm1
2 Inherits System.Web.UI.P age
3
4 #Region " Web Form Designer Generated Code "
5
6 'This call is required by the Web Form Designer.
7 <System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
8
9 End Sub
10 Protected WithEvents Button1 As System.Web.UI.W ebControls.Butt on
11
12 'NOTE: The following placeholder declaration is required by the Web Form Designer.
13 'Do not delete or move it.
14 Private designerPlaceho lderDeclaration As System.Object
15
16 Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
17 'CODEGEN: This method call is required by the Web Form Designer
18 'Do not modify it using the code editor.
19 InitializeCompo nent()
20 End Sub
21
22 #End Region
23
24 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
25 'Put user code to initialize the page here
26
27 Dim s As String = GetHtmlForContr ol(Button1)
28
29 End Sub
30 Public Function GetHtmlForContr ol(ByVal Control As System.Web.UI.C ontrol) As String
31
32
33 'Dim Tbx As New TextBox
34 'Tbx.Text = "Hello World!"
35 'Dim Writer As HtmlTextWriter = New HtmlTextWriter( New System.IO.Strin gWriter)
36 'Tbx.RenderCont rol(Writer)
37 'Dim s As String = Writer.InnerWri ter.ToString()
38
39 Dim Writer As System.Web.UI.H tmlTextWriter = New System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)
40 Control.RenderC ontrol(Writer)
41 Dim Htmltext As String = Writer.InnerWri ter.ToString()
42 Return Htmltext
43
44 End Function
45 End Class

Server Error in '/WebApplication1 ' Application.
------------------------------------------------------------------------------

Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Http Exception: Control 'Button1' of type 'Button' must be placed inside a form tag with runat=server.

Source Error:

Line 38:
Line 39: Dim Writer As System.Web.UI.H tmlTextWriter = New System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)
Line 40: Control.RenderC ontrol(Writer)
Line 41: Dim Htmltext As String = Writer.InnerWri ter.ToString()
Line 42: Return Htmltext

Source File: c:\inetpub\wwwr oot\WebApplicat ion1\WebForm1.a spx.vb Line: 40
Nov 19 '05 #2
You could do something like this (it's same idea, just for a different use):

http://staff.develop.com/ballen/blog...2-8095a848d821

-Brock
DevelopMentor
http://staff.develop.com/ballen
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 Controls.

You'll notice below in lines 33-37 that that code does correctlt
return the HTML for a textbox. How do I make it generic so it returns
the HTML for any control. Hopefully, if the control is a container
control, it will return the HTML for ALL nested controls, too.

When I hit line 40, I get the error: Control 'Button1' of type
'Button' must be placed inside a form tag with runat=server.

Thanks for any comments that may be offered.

Chad

1 Public Class WebForm1
2 Inherits System.Web.UI.P age
3
4 #Region " Web Form Designer Generated Code "
5
6 'This call is required by the Web Form Designer.
7 <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
8
9 End Sub
10 Protected WithEvents Button1 As
System.Web.UI.W ebControls.Butt on
11
12 'NOTE: The following placeholder declaration is required by
the Web Form Designer.
13 'Do not delete or move it.
14 Private designerPlaceho lderDeclaration As System.Object
15
16 Private Sub Page Init(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Init
17 'CODEGEN: This method call is required by the Web Form
Designer
18 'Do not modify it using the code editor.
19 InitializeCompo nent()
20 End Sub
21
22 #End Region
23
24 Private Sub Page Load(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles MyBase.Load
25 'Put user code to initialize the page here
26
27 Dim s As String = GetHtmlForContr ol(Button1)
28
29 End Sub
30 Public Function GetHtmlForContr ol(ByVal Control As
System.Web.UI.C ontrol) As String
31
32
33 'Dim Tbx As New TextBox
34 'Tbx.Text = "Hello World!"
35 'Dim Writer As HtmlTextWriter = New HtmlTextWriter( New
System.IO.Strin gWriter)
36 'Tbx.RenderCont rol(Writer)
37 'Dim s As String = Writer.InnerWri ter.ToString()
38
39 Dim Writer As System.Web.UI.H tmlTextWriter = New
System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)
40 Control.RenderC ontrol(Writer)
41 Dim Htmltext As String = Writer.InnerWri ter.ToString()
42 Return Htmltext
43
44 End Function
45 End Class
Server Error in '/WebApplication1 ' Application.
----------------------------------------------------------------------
--- -------

Control 'Button1' of type 'Button' must be placed inside a form tag
with runat=server. Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack
trace for more information about the error and where it originated in
the code.

Exception Details: System.Web.Http Exception: Control 'Button1' of type
'Button' must be placed inside a form tag with runat=server.

Source Error:

Line 38:
Line 39: Dim Writer As System.Web.UI.H tmlTextWriter = New
System.Web.UI.H tmlTextWriter(N ew System.IO.Strin gWriter)
Line 40: Control.RenderC ontrol(Writer)
Line 41: Dim Htmltext As String =
Writer.InnerWri ter.ToString()
Line 42: Return Htmltext
Source File: c:\inetpub\wwwr oot\WebApplicat ion1\WebForm1.a spx.vb
Line: 40

Nov 19 '05 #3

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

Similar topics

0
2853
by: rob | last post by:
I've been having a problem getting the text associated with checked items in a checkedlistbox control-- this article on MSDN shows how to do it: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskdeterminingcheckeditems.asp EXCEPT- it doesnt seem to work when you databind the control to a dataset. When you iterate through the checked items, you get "system.data.dataview" as the text.
0
1642
by: Kenneth | last post by:
Hi, I am implementing a VB program using webbrowser control. Whenever a user makes a selection on the webbrowser control, I will have to identify the location where this selected text resides in HTML. I can use document.selection.createrange.text to get the text but I can't find anything close for me to extract the HTML portion. Please kindly shed some lights if you have any solutions to this? Thanks in advance.
3
24679
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 situation is: A main window opens child windows one at a time as the user requests, each with its own name. The user may click in any child window or the main window to open a summary window, which has a name all windows know. I want to get that...
0
1350
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 form tag with runat=server." As you see, the controls HAVE been placed inside the <form runat="server"> tags. Please help me with this.
2
15611
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 focus. I'm trying to use the screen.activecontrol, with the oncurrent event, but am getting an error that the expression requires the control to be in the active window. im getting this error also when i move from one record to the next .
17
2469
by: Lloyd Sheen | last post by:
This IDE is driving me nuts. I needed another button so I copied an existing one, changed the Text and the id and position by drag and drop. Well then I run and get the following: Control 'Button19' of type 'Button' must be placed inside a form tag with runat=server Can the IDE not do what it is supposed to do. It seems that it is a fight to make it do anything or did I do something wrong? It would seem silly to have to create a...
2
2835
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 to it to view additional details about the selected result (a second database query is triggered). I want this second query to pop up in a new window, the way it would if I used "window.open" in javascript. I've added a function in the
8
13514
by: Amit | last post by:
I have a master page and a content page but the stylesheet isnt getting applied like how it looks in visual studio design view. The master page is defined like this: <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
1
4917
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in...
0
8253
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8354
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8497
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1499
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.