Selecteditem.value for a listbox in a user control

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Greetings,

How can I access the selecteditem.value property for a listbox that is in a
user control (.ascx) inside of my .aspx page? Thanks,

-Dave
 
Hello Dave,

If you need access to it from the page, you can do two things.

1: (Least desirable) Expose the listbox as a public variable from the ASCX
file
2. (Most desirable) Create a public property in your ASCX file and reference
the property from the ASPX

Example:

(in the .ascx)
public object ListBoxValue { get { return myListbox.SelectedItem.Value } }

(in the .aspx)
object o = myAscxControl.ListBoxValue;
 
Matt,

Thanks for the help. I have that part down now, but I must have another
issue (I can't reference the User Control from code, even though it shows up
fine). I posted it as a new post. If you can help me further on that, I
would be greatly appreciative. Thanks,

-Dave
 
Back
Top