Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass listbox selectedItem to javascript ?

Status
Not open for further replies.

snobrdinrtiste

Programmer
Aug 22, 2005
24
US
Hi everyone,
I'm a NooB to the ASP.NET world...
I looked all over but to no avail...
but my problem is this that i have an asp:listbox that when i select an item and then click on a asp:imagebutton, it will pass the selectedItem's value to a javascript function...
can someone help me?
here's something along of what i'm trying to accomplish:

this is my javascript;
function showItemSelected(theValue) {
window.alert(theValue);
}

<asp:Listbox id="listCD" runat="server"></asp:Listbox>
<asp:ImageButton id="imgBtnCD" runat="server" ImageUrl="Images/submit.gif"></asp:ImageButton>
 
You don't need ASP.NET Server Controls for any of that. Standard HTML and JavaScript will work just fine. Assuming though, that you need to use ASP.NET controls for a specific reason not mentioned, then you need to add a client-side handler to your ImageButton.

Use the "Add" method of the "Attributes" collection, to add the "onclick" attribute.

Code:
imgBtnCD.attributes.add("onclick","showItemSelected(listCD)");

Thomas D. Greer
 
Thomas,
The reason i need the asp listbox is because i'm using vb.net code to get the list of files in specific directory on the server...
what if i don't use the asp imagebutton and use just an image with the <a href> tags? Can i still retrieve the listbox's selectedItem.value?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top