properly adding multiple javascript attributes

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

On some of my pages I add a javascript call dynamically to the BODY tag:

pageBody.Attributes.add("onload", "dothis();")

Since this adds an actual attribute, trying to call this multiple times
simply replaces the attribute I created rather than adding new values to the
existing attribute. Which makes sense.

But what if I want to append values to a single attribute. What's the proper
way to do that?

One thought was to make a new variable or an array and add to that as the
value, but was wondering if there was a more direct method.

-Darrel
 
Can you maintain a list internally in your application then then add all of
them at once?
pageBody.Attributes.add("onload", "dothis1();dothis2();dothis3();")

or

pageBody.Attributes.add("onload", pageBody.Attributes["onload"]+"dothis();")

You might need () instead of [] in VB.NET. The latter example here might
give you an exception if pageBody.Attributes["onload"] is null or empty.

I would try option 1.

-Andrew
 
Back
Top