473,327 Members | 2,112 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,327 software developers and data experts.

Inherit from System.Web.UI.HtmlControls ??

Hi folks,

The pages of my website are built dynamically and are based on templates.

A template can look like this :

<table>
<tr><td>This is the page header</td></tr>
<tr><td>This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

People can modify the templates to suit their needs.

My problem is as follows :
Some people, when modifying the template, want to add some style definitions
using <STYLE>...</STYLE> and these style definitions should be put in the
heading of the page (<head>...</head> section).

To accomplish this, I've written a custom control (named "style") which will
copy the style section from the template to the page header.
The template now looks like this :

<emc:style runat="server">
<style>
.content {font-family:Arial,Verdana,Sans-serif; color:#ff0000;
font-size:10px;}
</style>
</emc:style>
<table>
<tr><td>This is the page header</td></tr>
<tr><td class="content">This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

Once the custom "style" control is executed, its "innerhtml" property (the
<style> itself) is read and copied to the pages header.
Here is the VB code for the custom "style" control :

Public Class Style
Inherits System.Web.UI.htmlcontrols.HtmlContainerControl

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Me.EnableViewState = False
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim headerControl As System.Web.UI.WebControls.PlaceHolder =
Page.FindControl("_head")
if not isNothing(headerControl) then
Dim newStyle As New
System.Web.UI.HtmlControls.HtmlGenericControl
newStyle.TagName = "STYLE"
newStyle.InnerText = Me.InnerHtml
headerControl.Controls.Add(newStyle)
newStyle = nothing
end if
headerControl = nothing

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
End Sub
End Class
This works fine ! However, I just read in a book from MS Press that we
should NEVER write a custom control that inherits from
System.Web.UI.htmlcontrols because they break the HTML Control Model. But I
have to inherit from this class because of the use of tge "innerHTML"
property in my code.

Can anybody help me out here ? Is there another solution for this ?

Thanks

Jill
Nov 18 '05 #1
3 4574
Hi,

having the innerhtml feature is same as adding a LiteralControl with the
HTML to the child controls (of your control).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Jill Graham" <ji**********@yahoo.com.au> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
Hi folks,

The pages of my website are built dynamically and are based on templates.

A template can look like this :

<table>
<tr><td>This is the page header</td></tr>
<tr><td>This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

People can modify the templates to suit their needs.

My problem is as follows :
Some people, when modifying the template, want to add some style definitions using <STYLE>...</STYLE> and these style definitions should be put in the
heading of the page (<head>...</head> section).

To accomplish this, I've written a custom control (named "style") which will copy the style section from the template to the page header.
The template now looks like this :

<emc:style runat="server">
<style>
.content {font-family:Arial,Verdana,Sans-serif; color:#ff0000;
font-size:10px;}
</style>
</emc:style>
<table>
<tr><td>This is the page header</td></tr>
<tr><td class="content">This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

Once the custom "style" control is executed, its "innerhtml" property (the <style> itself) is read and copied to the pages header.
Here is the VB code for the custom "style" control :

Public Class Style
Inherits System.Web.UI.htmlcontrols.HtmlContainerControl

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Me.EnableViewState = False
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim headerControl As System.Web.UI.WebControls.PlaceHolder = Page.FindControl("_head")
if not isNothing(headerControl) then
Dim newStyle As New
System.Web.UI.HtmlControls.HtmlGenericControl
newStyle.TagName = "STYLE"
newStyle.InnerText = Me.InnerHtml
headerControl.Controls.Add(newStyle)
newStyle = nothing
end if
headerControl = nothing

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
End Sub
End Class
This works fine ! However, I just read in a book from MS Press that we
should NEVER write a custom control that inherits from
System.Web.UI.htmlcontrols because they break the HTML Control Model. But I have to inherit from this class because of the use of tge "innerHTML"
property in my code.

Can anybody help me out here ? Is there another solution for this ?

Thanks

Jill

Nov 18 '05 #2
I don't think I understand what you mean...
Could you explain your point ?

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
Hi,

having the innerhtml feature is same as adding a LiteralControl with the
HTML to the child controls (of your control).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Jill Graham" <ji**********@yahoo.com.au> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
Hi folks,

The pages of my website are built dynamically and are based on templates.
A template can look like this :

<table>
<tr><td>This is the page header</td></tr>
<tr><td>This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

People can modify the templates to suit their needs.

My problem is as follows :
Some people, when modifying the template, want to add some style definitions
using <STYLE>...</STYLE> and these style definitions should be put in the heading of the page (<head>...</head> section).

To accomplish this, I've written a custom control (named "style") which

will
copy the style section from the template to the page header.
The template now looks like this :

<emc:style runat="server">
<style>
.content {font-family:Arial,Verdana,Sans-serif; color:#ff0000;
font-size:10px;}
</style>
</emc:style>
<table>
<tr><td>This is the page header</td></tr>
<tr><td class="content">This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

Once the custom "style" control is executed, its "innerhtml" property

(the
<style> itself) is read and copied to the pages header.
Here is the VB code for the custom "style" control :

Public Class Style
Inherits System.Web.UI.htmlcontrols.HtmlContainerControl

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
Me.EnableViewState = False
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim headerControl As

System.Web.UI.WebControls.PlaceHolder =
Page.FindControl("_head")
if not isNothing(headerControl) then
Dim newStyle As New
System.Web.UI.HtmlControls.HtmlGenericControl
newStyle.TagName = "STYLE"
newStyle.InnerText = Me.InnerHtml
headerControl.Controls.Add(newStyle)
newStyle = nothing
end if
headerControl = nothing

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
End Sub
End Class
This works fine ! However, I just read in a book from MS Press that we
should NEVER write a custom control that inherits from
System.Web.UI.htmlcontrols because they break the HTML Control Model.
But I
have to inherit from this class because of the use of tge "innerHTML"
property in my code.

Can anybody help me out here ? Is there another solution for this ?

Thanks

Jill


Nov 18 '05 #3
I mean that InnerHtml proeprty works with HTML controls that way. In the
property set accessor the given HTML string is instantiated into
LiteralControl which is added to the Controls collection of the control.
Therefore it means that you can get similar feature, but you can derive from
System.Web.UI.Control or System.Web.UI.WenControls.WebControl.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Jill Graham" <ji**********@yahoo.com.au> wrote in message
news:e%****************@tk2msftngp13.phx.gbl...
I don't think I understand what you mean...
Could you explain your point ?

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
Hi,

having the innerhtml feature is same as adding a LiteralControl with the
HTML to the child controls (of your control).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke

"Jill Graham" <ji**********@yahoo.com.au> wrote in message
news:Ok**************@TK2MSFTNGP11.phx.gbl...
Hi folks,

The pages of my website are built dynamically and are based on templates.
A template can look like this :

<table>
<tr><td>This is the page header</td></tr>
<tr><td>This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

People can modify the templates to suit their needs.

My problem is as follows :
Some people, when modifying the template, want to add some style

definitions
using <STYLE>...</STYLE> and these style definitions should be put in the heading of the page (<head>...</head> section).

To accomplish this, I've written a custom control (named "style") which
will
copy the style section from the template to the page header.
The template now looks like this :

<emc:style runat="server">
<style>
.content {font-family:Arial,Verdana,Sans-serif; color:#ff0000;
font-size:10px;}
</style>
</emc:style>
<table>
<tr><td>This is the page header</td></tr>
<tr><td class="content">This is the page content</td></tr>
<tr><td>This is the page footer</td></tr>
</table>

Once the custom "style" control is executed, its "innerhtml" property

(the
<style> itself) is read and copied to the pages header.
Here is the VB code for the custom "style" control :

Public Class Style
Inherits System.Web.UI.htmlcontrols.HtmlContainerControl

Private Sub Page_Init(ByVal sender As System.Object, ByVal e

As System.EventArgs) Handles MyBase.Init
Me.EnableViewState = False
End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim headerControl As

System.Web.UI.WebControls.PlaceHolder
=
Page.FindControl("_head")
if not isNothing(headerControl) then
Dim newStyle As New
System.Web.UI.HtmlControls.HtmlGenericControl
newStyle.TagName = "STYLE"
newStyle.InnerText = Me.InnerHtml
headerControl.Controls.Add(newStyle)
newStyle = nothing
end if
headerControl = nothing

Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
End Sub
End Class
This works fine ! However, I just read in a book from MS Press that we should NEVER write a custom control that inherits from
System.Web.UI.htmlcontrols because they break the HTML Control Model.

But
I
have to inherit from this class because of the use of tge "innerHTML"
property in my code.

Can anybody help me out here ? Is there another solution for this ?

Thanks

Jill



Nov 18 '05 #4

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

Similar topics

0
by: Jill Graham | last post by:
Hi folks, The pages of my website are built dynamically and are based on templates. A template can look like this : <table> <tr><td>This is the page header</td></tr> <tr><td>This is the...
0
by: Matrix - MAM | last post by:
I'm using the following code in my Web Application. private void Button1_Click(object sender, System.EventArgs e) { //sourceFile is id of System.Web.UI.HtmlControls.HtmlInputFile...
6
by: Mohammad-Reza | last post by:
I wrote a component using class library wizard. In my component i want to in order to RightToLeft property do some works. I can find out if user set this property to Yes or No, But if He/She set it...
5
by: Mike L | last post by:
This is my first attempt at inheriting a class. I want to inherit textbox class to my derived class ClassNum. ClassNum will override the TextChanged, Leave, KeyPress and Enter methods. So,...
10
by: tshad | last post by:
I have a problem setting the background color of textbox on the fly. I tried using: applicantID.backcolor = "F6F6F6" and applicantID.backcolor = "#F6F6F6"
2
by: Sean Carey | last post by:
I converted a C# Upload app to VB.NET and am down to one error and was hoping someone could help me with te error. I would greatly appreciate help from anyone. Here is the error: ...
8
by: Nathan Sokalski | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. After the file is successfully submitted, I want the field to be reset so that the user knows the file was...
3
by: J | last post by:
I tried to inherit 'Shot' class from 'Image' class, only to fail. It gives me the CS0122 error, which says that it can't access 'System.Drawing.Image.Image()'. What am I missing? using...
9
by: Arpan | last post by:
If I am not wrong, System.IO is one of the seven namespaces that get imported in all ASP.NET page automatically but in the following code: <%@ Import Namespace="System.IO" %> <script...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.