adding a javascript attribute to all text form elements on an asp.net page

K

Ken Fine

In code, I'm adding javascript attributes to form elements on an ASP.NET
page:

body.Attributes.Add("onClick", "highlight(event);");
body.Attributes.Add("onKeyUp", "highlight(event);");
title.Attributes.Add("onClick", "highlight(event);");
title.Attributes.Add("onKeyUp", "highlight(event);");
description.Attributes.Add("onKeyUp", "highlight(event);");
description.Attributes.Add("onClick", "highlight(event);");

I would like to know how to tell the renderer to generically apply the
onClick and onKeyUp attributes to all form elements that take text, rather
than naming those form elements in code, as I do here. The functional
equivalent of :

*.Attributes.Add("onClick", "highlight(event);");

Thanks,
-KF
 
E

Eliyahu Goldin

What about drilling down Controls collection starting from your page object
and adding the attributes depending on the control type? You can do it in
the PreRender event.
 
K

Ken Fine

Can someone pass along an analogous snip of code?

Thank you.

-KF

Eliyahu Goldin said:
What about drilling down Controls collection starting from your page
object and adding the attributes depending on the control type? You can do
it in the PreRender event.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]


Ken Fine said:
In code, I'm adding javascript attributes to form elements on an ASP.NET
page:

body.Attributes.Add("onClick", "highlight(event);");
body.Attributes.Add("onKeyUp", "highlight(event);");
title.Attributes.Add("onClick", "highlight(event);");
title.Attributes.Add("onKeyUp", "highlight(event);");
description.Attributes.Add("onKeyUp", "highlight(event);");
description.Attributes.Add("onClick", "highlight(event);");

I would like to know how to tell the renderer to generically apply the
onClick and onKeyUp attributes to all form elements that take text,
rather than naming those form elements in code, as I do here. The
functional equivalent of :

*.Attributes.Add("onClick", "highlight(event);");

Thanks,
-KF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top