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.Page
3
4 #Region " Web Form Designer Generated Code "
5
6 'This call is required by the Web Form Designer.
7 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
8
9 End Sub
10 Protected WithEvents Button1 As System.Web.UI.WebControls.Button
11
12 'NOTE: The following placeholder declaration is required by the Web Form Designer.
13 'Do not delete or move it.
14 Private designerPlaceholderDeclaration As System.Object
15
16 Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) 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 InitializeComponent()
20 End Sub
21
22 #End Region
23
24 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
25 'Put user code to initialize the page here
26
27 Dim s As String = GetHtmlForControl(Button1)
28
29 End Sub
30 Public Function GetHtmlForControl(ByVal Control As System.Web.UI.Control) 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.StringWriter)
36 'Tbx.RenderControl(Writer)
37 'Dim s As String = Writer.InnerWriter.ToString()
38
39 Dim Writer As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter)
40 Control.RenderControl(Writer)
41 Dim Htmltext As String = Writer.InnerWriter.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.HttpException: 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.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter)
Line 40: Control.RenderControl(Writer)
Line 41: Dim Htmltext As String = Writer.InnerWriter.ToString()
Line 42: Return Htmltext
Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line: 40 2 2335
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.EventArgs) 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(TableRow)
Dim C As New TableCell
TableRow.Cells.Add(C)
C.Controls.Add(B)
Dim HTML As String = GetHtmlForControl(T)
End Sub
Public Function GetHtmlForControl(ByVal Control As System.Web.UI.Control) As String
'Dim Tbx As New TextBox
'Tbx.Text = "Hello World!"
'Dim Writer As HtmlTextWriter = New HtmlTextWriter(New System.IO.StringWriter)
'Tbx.RenderControl(Writer)
'Dim s As String = Writer.InnerWriter.ToString()
Dim Writer As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter)
Control.RenderControl(Writer)
Dim Htmltext As String = Writer.InnerWriter.ToString()
Return Htmltext
End Function
"Chad" <ch**************@unisys.com> wrote in message news:dg**********@trsvr.tr.unisys.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.Page
3
4 #Region " Web Form Designer Generated Code "
5
6 'This call is required by the Web Form Designer.
7 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
8
9 End Sub
10 Protected WithEvents Button1 As System.Web.UI.WebControls.Button
11
12 'NOTE: The following placeholder declaration is required by the Web Form Designer.
13 'Do not delete or move it.
14 Private designerPlaceholderDeclaration As System.Object
15
16 Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) 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 InitializeComponent()
20 End Sub
21
22 #End Region
23
24 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
25 'Put user code to initialize the page here
26
27 Dim s As String = GetHtmlForControl(Button1)
28
29 End Sub
30 Public Function GetHtmlForControl(ByVal Control As System.Web.UI.Control) 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.StringWriter)
36 'Tbx.RenderControl(Writer)
37 'Dim s As String = Writer.InnerWriter.ToString()
38
39 Dim Writer As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter)
40 Control.RenderControl(Writer)
41 Dim Htmltext As String = Writer.InnerWriter.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.HttpException: 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.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter)
Line 40: Control.RenderControl(Writer)
Line 41: Dim Htmltext As String = Writer.InnerWriter.ToString()
Line 42: Return Htmltext
Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line: 40
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.Page 3 4 #Region " Web Form Designer Generated Code " 5 6 'This call is required by the Web Form Designer. 7 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() 8 9 End Sub 10 Protected WithEvents Button1 As System.Web.UI.WebControls.Button 11 12 'NOTE: The following placeholder declaration is required by the Web Form Designer. 13 'Do not delete or move it. 14 Private designerPlaceholderDeclaration As System.Object 15 16 Private Sub Page Init(ByVal sender As System.Object, ByVal e As System.EventArgs) 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 InitializeComponent() 20 End Sub 21 22 #End Region 23 24 Private Sub Page Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 25 'Put user code to initialize the page here 26 27 Dim s As String = GetHtmlForControl(Button1) 28 29 End Sub 30 Public Function GetHtmlForControl(ByVal Control As System.Web.UI.Control) 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.StringWriter) 36 'Tbx.RenderControl(Writer) 37 'Dim s As String = Writer.InnerWriter.ToString() 38 39 Dim Writer As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter) 40 Control.RenderControl(Writer) 41 Dim Htmltext As String = Writer.InnerWriter.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.HttpException: 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.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(New System.IO.StringWriter) Line 40: Control.RenderControl(Writer) Line 41: Dim Htmltext As String = Writer.InnerWriter.ToString() Line 42: Return Htmltext Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line: 40 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |