[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Using AddAttribute in different scopes with same attribute name...

(Christer)

1/21/2003 10:11:00 PM

Hi all!

I'm a situation, where I want to inherit from
System.Web.UI.Webcontrols.Textbox. In this new inherited textbox, I
want to add some javascript code on the onFocus event. No problem, I
do so by using AddAttribute on the HTMLTextWriter before rendering my
base class.

Now, I want create yet another textbox, that extends my new textbox
with more functionality... but, the functionality also uses onFocus.
So, I have use AddAttribute in this scope too.

The inheritance result is this
System.Web.UI.Webcontrols.Textbox -> MyTextBox1 (adds OnFocus script)
-> MyTextBox1 (adds (more) OnFocus script)

When I do this, it results in TWO onFocus attributes in the html
output. Does any of you know how to "append" to an existing attribute,
if it exists among the attributes, that haven't been written to a html
element yet? The situation above is simplified - the real one
justifies that the two are not implemented in the same class.

Thanks in advance.

Christer
1 Answer

Andy Smith

1/22/2003 9:19:00 PM

0

here's an example in c# for the second one

String myOnFocus = getOnFocusScript();
String originalOnFocus = this.Attributes["onfocus"];
if (originalOnFocus != null) {
myOnFocus = originalOnFocus + " " + myOnFocus;
}
this.Attributes["onfocus"] = myOnFocus;

this should work.

"Christer" <winterdk@hotmail.com> wrote in message
news:7beadfe3.0301210324.3909f96b@posting.google.com...
> Hi all!
>
> I'm a situation, where I want to inherit from
> System.Web.UI.Webcontrols.Textbox. In this new inherited textbox, I
> want to add some javascript code on the onFocus event. No problem, I
> do so by using AddAttribute on the HTMLTextWriter before rendering my
> base class.
>
> Now, I want create yet another textbox, that extends my new textbox
> with more functionality... but, the functionality also uses onFocus.
> So, I have use AddAttribute in this scope too.
>
> The inheritance result is this
> System.Web.UI.Webcontrols.Textbox -> MyTextBox1 (adds OnFocus script)
> -> MyTextBox1 (adds (more) OnFocus script)
>
> When I do this, it results in TWO onFocus attributes in the html
> output. Does any of you know how to "append" to an existing attribute,
> if it exists among the attributes, that haven't been written to a html
> element yet? The situation above is simplified - the real one
> justifies that the two are not implemented in the same class.
>
> Thanks in advance.
>
> Christer