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

  • Thread starter Thread starter Ken Fine
  • Start date Start date
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
 
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.
 
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
 
Back
Top