Click to See Complete Forum and Search --> : ASP.NET ListBox client side event


Xtreme.NET
02-24-2004, 09:48 PM
actually what i want to do is that i have two list boxes. when i click any one one a particular item, the other listbox's same idex item should get highlighted too.. producing a list of listview effect ie. whenever an item is clicked on either of the listboxes, the sames index item on the other listbox will get highlighted too..
to test this i made the below code to see how to integrate javascript in asp.NET

i made a list box and added a javascript function to it
i made the listbox
<asp:listbox id="lstFilter" Runat="server"></asp:listbox>
i added a javascript event to it on PageLoad
lstFilter.Attributes.Add("onchange", "SelectPair(window.document.form1.lstFilter.options[selectedIndex].text);")
then i wrote the javascript function :
<script language="javascript">
function SelectPair(window.document.form1.lstFilter.options[selectedIndex].text)
{
//lstvalue.select(
window.document.Form1.lstFilter.options[selectedIndex].text = "hahahah"
}
</script>
but nothing is working....can u pls help....
tks a lot...

PeOfEo
02-24-2004, 09:51 PM
this would probably be better suited for the asp section.

Xtreme.NET
02-24-2004, 09:56 PM
the problem is in javascript...asp.net has no prob whatsoever...
the client side programming(javascript) is the problem

PeOfEo
02-24-2004, 10:40 PM
well the <asp:listbox is just a glorified <option> with a runat="server". I feel that using the asp.net element offers a bit more control but if you were to handle it like an html element and drop in the runat="server" could you possibly do this easier? I stay away from java script, to be honest I do not even like it when the server outputs java script from my asp.net scripts (because asp.net 1.1 leaves off the type attribute!). I keep all working scripting server side and just do aesthetics client side. So if what you are doing is more then aesthetic you might want to consider doing a backup server side just incase the user does not have java script.

Xtreme.NET
02-24-2004, 10:49 PM
after myself you are the first guy i met who doesnt like javascript... just like me...
so you know my situation..
simple... two listboxes
click one, other listbox's same indes element gets highlighted
rendering a listview type effect
since we both dont like javascript, can u suggest a solution to achieve this??
everywhere i go they tell me to use javascript..
can u tell me what the appropriate solution for js haters like us?
tks

PeOfEo
02-24-2004, 11:00 PM
Well does this affect the functionality of your site? If it does not play with the working scripts of your site at all, then js would be fine for this. Js is fine for aesthetics, and conveiniant affects. For example the forum alerts the user the post is too long before they post it, rather then waiting for the user to be redirect to the next page with an error message which would be the plan b. The asp.net required feild validators work the same way (even though I use if statements to check and code the usual output in by hand with a type attribute). I do not want to write any js right now because it would be a pain for me not being a js enthusiast and take me longer then the others here, but to everyone who reads this, <asp:listbox can be though of as a <select>, because that is what will be outputted by the server.

Xtreme.NET
02-24-2004, 11:04 PM
did u read my post?>??:confused: after myself you are the first guy i met who doesnt like javascript... just like me...
so you know my situation..
simple... two listboxes
click one, other listbox's same indes element gets highlighted
rendering a listview type effect
since we both dont like javascript, can u suggest a solution to achieve this??
everywhere i go they tell me to use javascript..
can u tell me what the appropriate solution for js haters like us?
tks


cause your answers doesnt seem related to my question...
i never asked you to write any JS at all...did I?:confused:

PeOfEo
02-24-2004, 11:08 PM
Originally posted by Xtreme.NET
did u read my post?>??:confused:
cause your answers doesnt seem related to my question...
i never asked you to write any JS at all...did I?:confused: Lol I did read your post, I said js is the answer did I not? If the scripting is just adding conveniance but your site can work without it then java script is fine. But I am not going to be able to help you come up with a java script because I am not that awesome with java script because I never use it. Then I mentioned that the asp.net element you are using outputs the html element the js people will need to know about if they are the ones giving you codeing advice.

Xtreme.NET
02-24-2004, 11:11 PM
i think i wasnt articulate enough...
now lets say i am not using js at all....
so can i simulate the situation above using asp.net??

PeOfEo
02-24-2004, 11:15 PM
Originally posted by Xtreme.NET
i think i wasnt articulate enough...
now lets say i am not using js at all....
so can i simulate the situation above using asp.net?? No, you can write scripts in asp.net that output javascript but this would be an inefficient way to do this. ASP.NET is an odd creature at times in that it runs server side but does a lot of client side output. This client side output is not neccessary to the functionality, but it does add conveiniance for the user, but I keep away from it when i can because this client side output tends to have validity issues and it is more rewarding to code the js by hand. But asp.net itself runs server side so to do anything like this in asp.net would be terrible because the page would have to be resent every time an option value is changed. Client side == not refreshing all the time, but bad for functionality, server side == functional but can be annoying for aesthetic issues.

razorfire
07-11-2004, 09:32 PM
you may want to try using the autopostback of the listbox attribute,
get the index of the selected item and assigned it to the second listbox.selectedItem attribute. it goes somewhat like this:

Inside ListBox1_SelectedIndexChanged sub routine:
ListBox2.SelectedIndex = ListBox1.SelectedIndex
ListBox2.SelectedItem.Selected = true

I Don't really know it will work, but you can try it out no doubt! Its only a suggestion and maybe you can work on it...Cos i'm using this to get values from other listbox which has relative information to the first listbox... .