473,808 Members | 2,851 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

properly adding multiple javascript attributes

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

pageBody.Attrib utes.add("onloa d", "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
Nov 22 '05 #1
1 2000
Can you maintain a list internally in your application then then add all of
them at once?
pageBody.Attrib utes.add("onloa d", "dothis1();doth is2();dothis3() ;")

or

pageBody.Attrib utes.add("onloa d", pageBody.Attrib utes["onload"]+"dothis();" )

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

I would try option 1.

-Andrew
"darrel" <no*****@nowher e.com> wrote in message
news:u$******** *****@TK2MSFTNG P09.phx.gbl...
On some of my pages I add a javascript call dynamically to the BODY tag:

pageBody.Attrib utes.add("onloa d", "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

Nov 22 '05 #2

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

Similar topics

4
5485
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new dropdownlist to the screen for selection. This continues until there are no children, and then it checks for a help article list based on that last selection and displays actual articles for display. Adding the controls and getting everything...
4
5592
by: Dmitry Korolyov [MVP] | last post by:
When we use btnSubmit.Attributes = "javascript: this.disabled=true;" to make the button disabled and prevent users from clicking it again while form data still posting, there is no longer postback. I.e. the button does go disabled, but the form does not invoke submit() method. Of course, it does work fine without this property. Clues?
19
2486
by: Sjaakie Helderhorst | last post by:
Hello, I need to add a Javascript event (onClick) to a servercontrol (asp:checkbox). Checkbox is named 'cbDoMail'. Assumed that 'cbDoMail.Attributes.Add("onClick", "doJavascriptThing()") would do the job, unfortunately it didn't. Can anyone point me in the right direction? Thanks!
3
4232
by: A Traveler | last post by:
Hello, I have a textbox in a datagrid row which has autopostback. When it posts back, it updates a prop on an object in a session variable. In order to update the right object, in the ItemDataBound of the grid, i was adding the objects ID property as a MyTextbox.Attributes.Add("recid",rowDataItemObj.RecID) along with several other attributes. For some reason these attributes are not being added the first time through.
8
2819
by: Nathan Sokalski | last post by:
I add a JavaScript event handler to some of my Webcontrols using the Attributes.Add() method as follows: Dim jscode as String = "return (event.keyCode>=65&&event.keyCode<=90);" TextBox2.Attributes.Add("onKeyPress", jscode) You will notice that jscode contains the JavaScript Logical And operator (&&). However, ASP.NET renders this as &amp;&amp; in the code that is
2
5958
by: darrel | last post by:
I am using a javascript WYSIWYG text editor for our CMS. To grab the proper content we need to add a javacsript call to the form: Form1.Attributes.Add("onSubmit", "myOnSubmitEventHandler();") That works fine. However, we also have some dropDownLists that trigger a postback. If we change these, I still need to update the text editor, so I added attributes to them:
2
3120
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so that it may help others. If posting this script is against the rules in this group then please accept my appologies. I developped this script so that I can add and remove rows in a table in which I have various input fields and I would use the...
2
2227
by: Ken Fine | last post by:
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);");
0
1111
by: samymsc15 | last post by:
hai... i have big problem by using javascript in c# code behind .. that is i have a multiple function in javascript... for example 3 functions.. at the c# code behind page;; button1.attributes.add("onclick","return function1()");; this is return only one function values but i need all of 3 function return values from javascript at that click... ple any one have any idea ple help me....
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10631
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10374
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10374
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.