473,396 Members | 2,029 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.

Modify HTML Generated By Server Controls

Technically speaking, this issue is not about modifying the HTML
generated by server controls but preceding the HTML generated by
server controls with an HTML control generated on the basis of the
type and the context of the server control itself. Clear as mud? :-)

Consider the following server control...
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

TextBox renders at run-time as an HTML control...
<input name="MemberEmail" type="text" id="MemberEmail" ... />

Section508 Accessibility requires the TextBox server control to
be preceded by the following HTML control...
<label for="MemberEmail">E-mail:</label>
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

As I understand it, at run-time, a screen reader will stop on the
HTML label control named 'MemberEmail', read it aloud and put
the focus on the rendered input control allowing the person to enter
data into the form field.

Preceding the TextBox Server Control with a Label Server Control
is out of the question as the screen reader will not read what the
Label Server Control renders at run-time...
<span id="lblMemberEmail">E-mail</span>

I can get properties of the TextBox control(s) using...
foreach (Control ctl in parent.Controls) ...and I can use those properties
to build the HTML label control but I don't know how to output and
render the HTML label control so it will precede its respectively rendered
TextBox control in the HTML that is generated when the TextBox
Server Control is rendered ar run-time.

I hope this makes sense and somebody can comment as it is much more
effective to automate a page to validate and function as Section508
accessible
than to write each HTML label control manually.
--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

Nov 18 '05 #1
4 1950
Clinton,
I handled the FOR compliance by creating a custom control, not sure if
that'll work for you..

Imports System.Web.UI.WebControls

Public Class ForLabel
Inherits Label

Private _for As String
Public Property [For]() As String
Get
Return _for
End Get
Set(ByVal Value As String)
_for = Value
End Set
End Property

Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Label
End Get
End Property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.AddAttribute(HtmlTextWriterAttribute.For, ClientID.Substring(0,
ClientID.Length - ID.Length) & _for)
MyBase.Render(writer)
End Sub

End Class
and then using it via:
<%@ Register TagPrefix="compliant" NameSpace="YOURNAMESPACE"
Assembly="YOURASSEMBLY" %>

<compliant:ForLabel runat="server" id="emailLabel" text="Email" For="Email"
/> <asp:TextBox ID="Email" Runat="server" />
Basically the FOR of the ForLabel will point to the ID of the textbox. It's
pretty basic, but ought to work so long as your label and your control is at
the same level (ie, don' tput the label on a page with the FOR poiting to a
textbox in a usercontrol)

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
Technically speaking, this issue is not about modifying the HTML
generated by server controls but preceding the HTML generated by
server controls with an HTML control generated on the basis of the
type and the context of the server control itself. Clear as mud? :-)

Consider the following server control...
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

TextBox renders at run-time as an HTML control...
<input name="MemberEmail" type="text" id="MemberEmail" ... />

Section508 Accessibility requires the TextBox server control to
be preceded by the following HTML control...
<label for="MemberEmail">E-mail:</label>
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

As I understand it, at run-time, a screen reader will stop on the
HTML label control named 'MemberEmail', read it aloud and put
the focus on the rendered input control allowing the person to enter
data into the form field.

Preceding the TextBox Server Control with a Label Server Control
is out of the question as the screen reader will not read what the
Label Server Control renders at run-time...
<span id="lblMemberEmail">E-mail</span>

I can get properties of the TextBox control(s) using...
foreach (Control ctl in parent.Controls) ...and I can use those properties
to build the HTML label control but I don't know how to output and
render the HTML label control so it will precede its respectively rendered
TextBox control in the HTML that is generated when the TextBox
Server Control is rendered ar run-time.

I hope this makes sense and somebody can comment as it is much more
effective to automate a page to validate and function as Section508
accessible
than to write each HTML label control manually.
--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


Nov 18 '05 #2
Thanks Karl. Your 'multilingual' Code Project articles are outstanding
and on my To-Do list. First things first...

Does this custom control you've developed actually write the <label>
element into the output stream so it will immediately precede the
<input> element when source is viewed?

<%= Clinton

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:%2***************@TK2MSFTNGP11.phx.gbl...
Clinton,
I handled the FOR compliance by creating a custom control, not sure if
that'll work for you..

Imports System.Web.UI.WebControls

Public Class ForLabel
Inherits Label

Private _for As String
Public Property [For]() As String
Get
Return _for
End Get
Set(ByVal Value As String)
_for = Value
End Set
End Property

Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Label
End Get
End Property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.AddAttribute(HtmlTextWriterAttribute.For, ClientID.Substring(0, ClientID.Length - ID.Length) & _for)
MyBase.Render(writer)
End Sub

End Class
and then using it via:
<%@ Register TagPrefix="compliant" NameSpace="YOURNAMESPACE"
Assembly="YOURASSEMBLY" %>

<compliant:ForLabel runat="server" id="emailLabel" text="Email" For="Email" /> <asp:TextBox ID="Email" Runat="server" />
Basically the FOR of the ForLabel will point to the ID of the textbox. It's pretty basic, but ought to work so long as your label and your control is at the same level (ie, don' tput the label on a page with the FOR poiting to a textbox in a usercontrol)

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:O4**************@TK2MSFTNGP09.phx.gbl...
Technically speaking, this issue is not about modifying the HTML
generated by server controls but preceding the HTML generated by
server controls with an HTML control generated on the basis of the
type and the context of the server control itself. Clear as mud? :-)

Consider the following server control...
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

TextBox renders at run-time as an HTML control...
<input name="MemberEmail" type="text" id="MemberEmail" ... />

Section508 Accessibility requires the TextBox server control to
be preceded by the following HTML control...
<label for="MemberEmail">E-mail:</label>
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

As I understand it, at run-time, a screen reader will stop on the
HTML label control named 'MemberEmail', read it aloud and put
the focus on the rendered input control allowing the person to enter
data into the form field.

Preceding the TextBox Server Control with a Label Server Control
is out of the question as the screen reader will not read what the
Label Server Control renders at run-time...
<span id="lblMemberEmail">E-mail</span>

I can get properties of the TextBox control(s) using...
foreach (Control ctl in parent.Controls) ...and I can use those properties to build the HTML label control but I don't know how to output and
render the HTML label control so it will precede its respectively rendered TextBox control in the HTML that is generated when the TextBox
Server Control is rendered ar run-time.

I hope this makes sense and somebody can comment as it is much more
effective to automate a page to validate and function as Section508
accessible
than to write each HTML label control manually.
--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/



Nov 18 '05 #3
Thanks clinton :)

It does write out the <label> element (as you can see it overrides the
TagKey property to do this), but it doesn't automatically place it anywhere.
That's why you still need to position it in the aspx file:

<table>
<tr>
<td><compliant:ForLabel runat="server" id="emailLabel" text="Email"
For="Email" /></td>
<td> <asp:TextBox ID="Email" Runat="server" /></td>
</tr>
</table>

For this reason I wasn't sure if this solution fit your needs.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:r7*******************@twister.rdc-kc.rr.com...
Thanks Karl. Your 'multilingual' Code Project articles are outstanding
and on my To-Do list. First things first...

Does this custom control you've developed actually write the <label>
element into the output stream so it will immediately precede the
<input> element when source is viewed?

<%= Clinton

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:%2***************@TK2MSFTNGP11.phx.gbl...
Clinton,
I handled the FOR compliance by creating a custom control, not sure if
that'll work for you..

Imports System.Web.UI.WebControls

Public Class ForLabel
Inherits Label

Private _for As String
Public Property [For]() As String
Get
Return _for
End Get
Set(ByVal Value As String)
_for = Value
End Set
End Property

Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Label
End Get
End Property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.AddAttribute(HtmlTextWriterAttribute.For, ClientID.Substring(0,
ClientID.Length - ID.Length) & _for)
MyBase.Render(writer)
End Sub

End Class
and then using it via:
<%@ Register TagPrefix="compliant" NameSpace="YOURNAMESPACE"
Assembly="YOURASSEMBLY" %>

<compliant:ForLabel runat="server" id="emailLabel" text="Email"

For="Email"
/> <asp:TextBox ID="Email" Runat="server" />
Basically the FOR of the ForLabel will point to the ID of the textbox.

It's
pretty basic, but ought to work so long as your label and your control is at
the same level (ie, don' tput the label on a page with the FOR poiting to
a
textbox in a usercontrol)

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in

message news:O4**************@TK2MSFTNGP09.phx.gbl...
Technically speaking, this issue is not about modifying the HTML
generated by server controls but preceding the HTML generated by
server controls with an HTML control generated on the basis of the
type and the context of the server control itself. Clear as mud? :-)

Consider the following server control...
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

TextBox renders at run-time as an HTML control...
<input name="MemberEmail" type="text" id="MemberEmail" ... />

Section508 Accessibility requires the TextBox server control to
be preceded by the following HTML control...
<label for="MemberEmail">E-mail:</label>
<asp:textbox id="MemberEmail" runat="server" ></asp:textbox>

As I understand it, at run-time, a screen reader will stop on the
HTML label control named 'MemberEmail', read it aloud and put
the focus on the rendered input control allowing the person to enter
data into the form field.

Preceding the TextBox Server Control with a Label Server Control
is out of the question as the screen reader will not read what the
Label Server Control renders at run-time...
<span id="lblMemberEmail">E-mail</span>

I can get properties of the TextBox control(s) using...
foreach (Control ctl in parent.Controls) ...and I can use those

properties to build the HTML label control but I don't know how to output and
render the HTML label control so it will precede its respectively rendered TextBox control in the HTML that is generated when the TextBox
Server Control is rendered ar run-time.

I hope this makes sense and somebody can comment as it is much more
effective to automate a page to validate and function as Section508
accessible
than to write each HTML label control manually.
--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/




Nov 18 '05 #4
Thanks for your attention Karl. After reading some DHTML
documentation such as outerHTML that allows entire HTML
declarations to be replaced in their entirety I imagined the same
could be done via ASP.NET.

There are significant requirements that must be achieved to validate
an ASP.NET application as accessible. The HTML required for
Section508 compliance *must* be well formed (easy) and it *must*
be located in the output source at a specific location preceding the
control it acts upon (difficult and able to do so yet to be determined)
and in the case of DropDownList controls (DDL) the required
Section508 HTML *must* be embedded into one or more locations
of the HTML that the DDL outputs at run-time.

There are many articles that address the general principles of accessiblity
when using ASP.NET but I have yet to find even one that can be used
to actually meet the requirements so the page can be validated.

--
<%= Clinton Gallagher, "Twice the Results -- Half the Cost"
Architectural & e-Business Consulting -- Software Development
NET cs*********@REMOVETHISTEXTmetromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/


"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:%2****************@TK2MSFTNGP10.phx.gbl...
Thanks clinton :)

It does write out the <label> element (as you can see it overrides the
TagKey property to do this), but it doesn't automatically place it anywhere. That's why you still need to position it in the aspx file:

<table>
<tr>
<td><compliant:ForLabel runat="server" id="emailLabel" text="Email"
For="Email" /></td>
<td> <asp:TextBox ID="Email" Runat="server" /></td>
</tr>
</table>

For this reason I wasn't sure if this solution fit your needs.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in message
news:r7*******************@twister.rdc-kc.rr.com...
Thanks Karl. Your 'multilingual' Code Project articles are outstanding
and on my To-Do list. First things first...

Does this custom control you've developed actually write the <label>
element into the output stream so it will immediately precede the
<input> element when source is viewed?

<%= Clinton

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:%2***************@TK2MSFTNGP11.phx.gbl...
Clinton,
I handled the FOR compliance by creating a custom control, not sure if
that'll work for you..

Imports System.Web.UI.WebControls

Public Class ForLabel
Inherits Label

Private _for As String
Public Property [For]() As String
Get
Return _for
End Get
Set(ByVal Value As String)
_for = Value
End Set
End Property

Protected Overrides ReadOnly Property TagKey() As
System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Label
End Get
End Property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.AddAttribute(HtmlTextWriterAttribute.For,

ClientID.Substring(0,
ClientID.Length - ID.Length) & _for)
MyBase.Render(writer)
End Sub

End Class
and then using it via:
<%@ Register TagPrefix="compliant" NameSpace="YOURNAMESPACE"
Assembly="YOURASSEMBLY" %>

<compliant:ForLabel runat="server" id="emailLabel" text="Email"

For="Email"
/> <asp:TextBox ID="Email" Runat="server" />
Basically the FOR of the ForLabel will point to the ID of the textbox.

It's
pretty basic, but ought to work so long as your label and your control

is
at
the same level (ie, don' tput the label on a page with the FOR poiting

to
a
textbox in a usercontrol)

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/
"clintonG" <cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote in

message news:O4**************@TK2MSFTNGP09.phx.gbl...
> Technically speaking, this issue is not about modifying the HTML
> generated by server controls but preceding the HTML generated by
> server controls with an HTML control generated on the basis of the
> type and the context of the server control itself. Clear as mud? :-)
>
> Consider the following server control...
> <asp:textbox id="MemberEmail" runat="server" ></asp:textbox>
>
> TextBox renders at run-time as an HTML control...
> <input name="MemberEmail" type="text" id="MemberEmail" ... />
>
> Section508 Accessibility requires the TextBox server control to
> be preceded by the following HTML control...
> <label for="MemberEmail">E-mail:</label>
> <asp:textbox id="MemberEmail" runat="server" ></asp:textbox>
>
> As I understand it, at run-time, a screen reader will stop on the
> HTML label control named 'MemberEmail', read it aloud and put
> the focus on the rendered input control allowing the person to enter
> data into the form field.
>
> Preceding the TextBox Server Control with a Label Server Control
> is out of the question as the screen reader will not read what the
> Label Server Control renders at run-time...
> <span id="lblMemberEmail">E-mail</span>
>
> I can get properties of the TextBox control(s) using...
> foreach (Control ctl in parent.Controls) ...and I can use those

properties
> to build the HTML label control but I don't know how to output and
> render the HTML label control so it will precede its respectively

rendered
> TextBox control in the HTML that is generated when the TextBox
> Server Control is rendered ar run-time.
>
> I hope this makes sense and somebody can comment as it is much more
> effective to automate a page to validate and function as Section508
> accessible
> than to write each HTML label control manually.
>
>
> --
> <%= Clinton Gallagher, "Twice the Results -- Half the Cost"
> Architectural & e-Business Consulting -- Software Development > NET cs*********@REMOVETHISTEXTmetromilwaukee.com
> URL http://www.metromilwaukee.com/clintongallagher/
>
>
>
>
>



Nov 18 '05 #5

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

Similar topics

2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
3
by: sviau | last post by:
how can i enforce compliancy on the code that asp.net generates. the ids are generated by asp.net http://validator.w3.org/check?uri=http%3A%2F%2Fwww.mls.ca%2FREALTORSearch.aspx ex: 1.. Line...
2
by: leila | last post by:
I am developing an ASP.Net application for a client and they need to modify the page layout from within a form. like the way you edit a blog template in Blogger. what is the best approach to do...
0
by: aeshtry | last post by:
Hello dear friends I have an urgent question. Would you please give me your professional idea? I have an html table containing the ASP.Net validation summary and an ASP.Net label control. The...
2
by: Giedrius | last post by:
hi, i have an idea to make admin tool on home computer, that would generate html files using some kind of templates and database data and put these generated html files to public web server, witch...
6
by: Rolf Welskes | last post by:
Hello, if I have for example: <table style="width: 100%; height: 100%;" border="1"> <tr> <td style="width: 100px">k </td> <td style="width: 100px">k </td> </tr>
2
by: Lucky | last post by:
hi guys! i've got very interesting problem. it is like this. is it possible to get HTML generated by the server control in code behind? i'm developing an asp.net web application where i need to...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
2
by: Will | last post by:
I'm interested in people's views on combining standard html controls and asp.net server controls. I've seen some applications where server controls were only used where server side processing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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,...
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.