473,396 Members | 1,879 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,396 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
Jul 21 '05 #1
0 1331

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

Similar topics

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...
3
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...
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: ...
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...
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: 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...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.