Click to See Complete Forum and Search --> : Asp.net Listbox click or more
drewex
03-31-2004, 02:53 PM
Hi all,
I just started using .net. I want to do everythin that i can do in javascript in .net there should be away to add listbox click event is there a way to this using .net
ps: I'm usin vb if replies are in vb that would be great for me. THanks all
PeOfEo
03-31-2004, 06:12 PM
<script runat="server">
Sub listboxid_Click(Sender As Object, E As EventArgs)
the code to be executed
end sub
</script>
asp.net runs server side, so when using this you are not going to have the code fire all nice and pretty like js where text will instantly appear or whatever, but rather the code will have to be executed by the server and the page will be refreshed. Server side scripting is more for functionality then aesthetics, java script and asp.net are very different. Also you can have more subs in a script running at the server.
drewex
03-31-2004, 06:26 PM
the problem is the click doesnt show in the method box in studio.net and thought there is none. Is there a place that i can look for the list.
I have studio.net 2003
have any ideas
PeOfEo
03-31-2004, 09:50 PM
I am using dw, not visual studio, and its been a long time since vb6... but I could have sworn click was an attribute. Ill look this up. I know onchange and a bunch of others are there though.
http://codeproject.com/vb/net/subclassing_listbox.asp
yep still is there
onclick="sub listbox_click". I am going to test it right now just incase I am wrong about this. Ok... nothing happens, guess not. Ok apparently there is an onclick event still with just vb.net but when you are using vb.net for asp.net it disappears on you, so you can only use that in client aps I guess , it was not in dreamweaver either and when I typed it nothing happened. Ok so what exactly are you trying to do and we can find an acceptable alternative. You can use selectedindexchange. I played around, and come to think of it a lot of elements that had the onclick attribute back in vb do not have it when you use asp.net... you learn something new everyday. Since a listbox is a form element I though if you used the client side event handler onblur and made it runat="server" it might work, but this is not the case.:(
drewex
04-01-2004, 12:10 PM
How does .net call the selectedindexchange. It should call some kind of client code that calles the server right? if im right it calls a javascript code. if we can find something that makes the same code. like
onclick="callserver(e event)"
or something like that we could use this any where we want
I dont want to go back to javascript. and there should be away to catch these stuff.
PeOfEo
04-01-2004, 06:16 PM
No, you are not going to be playing with client side code at all. It resends the whole thing back to the server through way of the form action, and all of your <asp:elements are running in a form runat="server". If you view your html output you will see
<form id="the id you specified" name="the name you specified" action="pagename.aspx"
if you did not specify a name or id the server would gen one... mine tend to look like _ctl10 when I do not specify a name (this also causes the html to be invalid, a _ cant be part of the id apparently).
<asp:listbox id="youbox" runat="server" OnSelectedIndexChanged="sub youbox_indexchange"></asp:listbox>
That is what the code will look like for onselectedindexchanged.