Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > listbox click - nothing happens?

Reply
Thread Tools

listbox click - nothing happens?

 
 
Steve
Guest
Posts: n/a
 
      08-19-2004
Hi,

I open up a webform (vb.net) and populate a listbox
control on the Page load event. If I click on (select)
and item from the listbox I want to write the value of the
selected item to a label control. Nothing happens. But
when I click a button (which contains same code to write
to label) I get the value of the selected item in the
Label.

I looked at the html portion of my webform and don't see a
listing for the onclick event of the button. So, do I
need to manually enter the "SelectedIndexChanged" event in
the html for the listbox?

<asp:listbox id="lstProducts" style="Z-INDEX: 101; LEFT:
48px; POSITION: absolute; TOP: 80px"runat="server"
Height="192px" Width="400px"></asp:listbox>

Thanks,
Steve
 
Reply With Quote
 
 
 
 
Karl
Guest
Posts: n/a
 
      08-19-2004
Yes, you do. You need to set the listbox's AutoPostBack property to true
and hook up the SelectedIndexChange event to a method.

Karl

"Steve" <(E-Mail Removed)> wrote in message
news:94a901c4863c$a99b3f20$(E-Mail Removed)...
> Hi,
>
> I open up a webform (vb.net) and populate a listbox
> control on the Page load event. If I click on (select)
> and item from the listbox I want to write the value of the
> selected item to a label control. Nothing happens. But
> when I click a button (which contains same code to write
> to label) I get the value of the selected item in the
> Label.
>
> I looked at the html portion of my webform and don't see a
> listing for the onclick event of the button. So, do I
> need to manually enter the "SelectedIndexChanged" event in
> the html for the listbox?
>
> <asp:listbox id="lstProducts" style="Z-INDEX: 101; LEFT:
> 48px; POSITION: absolute; TOP: 80px"runat="server"
> Height="192px" Width="400px"></asp:listbox>
>
> Thanks,
> Steve



 
Reply With Quote
 
 
 
 
Steve
Guest
Posts: n/a
 
      08-19-2004
Well I modified my listbox tag (which now works) as follows

<asp:listbox id="lstProducts" style="Z-INDEX: 101; LEFT:
48px; POSITION: absolute; TOP: 80px" autopostback="True"
OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
runat="server" Height="192px" Width="400px"></asp:listbox>

I added autopostback="True" and then called the sub
OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"

But I had to remove the Private keyword from the sub.
Question: is it standard convention then to use
autopostback="true" to invoke subs for aspx? this did
not seem real intuitive to me.

Thanks,
Steve

>-----Original Message-----
>Hi,
>
>I open up a webform (vb.net) and populate a listbox
>control on the Page load event. If I click on (select)
>and item from the listbox I want to write the value of

the
>selected item to a label control. Nothing happens. But
>when I click a button (which contains same code to write
>to label) I get the value of the selected item in the
>Label.
>
>I looked at the html portion of my webform and don't see

a
>listing for the onclick event of the button. So, do I
>need to manually enter the "SelectedIndexChanged" event

in
>the html for the listbox?
>
><asp:listbox id="lstProducts" style="Z-INDEX: 101; LEFT:
>48px; POSITION: absolute; TOP: 80px"runat="server"
>Height="192px" Width="400px"></asp:listbox>
>
>Thanks,
>Steve
>.
>

 
Reply With Quote
 
Karl
Guest
Posts: n/a
 
      08-19-2004
What you are doing is standard convention. Perhaps they made the default to
false because (a) it's how things have worked in the past (b) there is a
performance penalty (you are hitting the server again), so they want you to
consciouly acknowledge that this is what you are doing.

You can keep the sub private, and remove the
OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged" from the tag and
instead declare the lstProducts in your codebehind with the "WithEvents"
keyword and declare your sub something like

private sub...() Handles lstProducts.SelectedIndexChange

Differences are trivial so consider it more a matter of preference.

Karl

"Steve" <(E-Mail Removed)> wrote in message
news:94f301c48641$e6bf7600$(E-Mail Removed)...
> Well I modified my listbox tag (which now works) as follows
>
> <asp:listbox id="lstProducts" style="Z-INDEX: 101; LEFT:
> 48px; POSITION: absolute; TOP: 80px" autopostback="True"
> OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
> runat="server" Height="192px" Width="400px"></asp:listbox>
>
> I added autopostback="True" and then called the sub
> OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
>
> But I had to remove the Private keyword from the sub.
> Question: is it standard convention then to use
> autopostback="true" to invoke subs for aspx? this did
> not seem real intuitive to me.
>
> Thanks,
> Steve
>
> >-----Original Message-----
> >Hi,
> >
> >I open up a webform (vb.net) and populate a listbox
> >control on the Page load event. If I click on (select)
> >and item from the listbox I want to write the value of

> the
> >selected item to a label control. Nothing happens. But
> >when I click a button (which contains same code to write
> >to label) I get the value of the selected item in the
> >Label.
> >
> >I looked at the html portion of my webform and don't see

> a
> >listing for the onclick event of the button. So, do I
> >need to manually enter the "SelectedIndexChanged" event

> in
> >the html for the listbox?
> >
> ><asp:listbox id="lstProducts" style="Z-INDEX: 101; LEFT:
> >48px; POSITION: absolute; TOP: 80px"runat="server"
> >Height="192px" Width="400px"></asp:listbox>
> >
> >Thanks,
> >Steve
> >.
> >



 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      08-20-2004
Thanks for the explanation. I took a class in asp.net
last spring (short course). Now I have to start using
it. May I ask what the WithEvents version of your
explanation would look like?

I noticed that I didn't have to deal with this with the
button. I am guessing the button has different rules
than a listbox. So for WithEvents


Dim lst1 As ListBox1 WithEvents

....

Private Sub ListBox1_SelectedIndexChanged(...)
....
End Sub

something like this? I already have something that
works, but only in the blind. Just trying to grasp some
understanding.

Thanks for your reply,
Steve


>-----Original Message-----
>What you are doing is standard convention. Perhaps they

made the default to
>false because (a) it's how things have worked in the

past (b) there is a
>performance penalty (you are hitting the server again),

so they want you to
>consciouly acknowledge that this is what you are doing.
>
>You can keep the sub private, and remove the
>OnSelectedIndexChanged="lstProducts_SelectedIndex Changed"

from the tag and
>instead declare the lstProducts in your codebehind with

the "WithEvents"
>keyword and declare your sub something like
>
>private sub...() Handles lstProducts.SelectedIndexChange
>
>Differences are trivial so consider it more a matter of

preference.
>
>Karl
>
>"Steve" <(E-Mail Removed)> wrote in

message
>news:94f301c48641$e6bf7600$(E-Mail Removed)...
>> Well I modified my listbox tag (which now works) as

follows
>>
>> <asp:listbox id="lstProducts" style="Z-INDEX: 101;

LEFT:
>> 48px; POSITION: absolute; TOP: 80px"

autopostback="True"
>>

OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
>> runat="server" Height="192px"

Width="400px"></asp:listbox>
>>
>> I added autopostback="True" and then called the sub
>>

OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
>>
>> But I had to remove the Private keyword from the sub.
>> Question: is it standard convention then to use
>> autopostback="true" to invoke subs for aspx? this did
>> not seem real intuitive to me.
>>
>> Thanks,
>> Steve
>>
>> >-----Original Message-----
>> >Hi,
>> >
>> >I open up a webform (vb.net) and populate a listbox
>> >control on the Page load event. If I click on

(select)
>> >and item from the listbox I want to write the value of

>> the
>> >selected item to a label control. Nothing happens.

But
>> >when I click a button (which contains same code to

write
>> >to label) I get the value of the selected item in the
>> >Label.
>> >
>> >I looked at the html portion of my webform and don't

see
>> a
>> >listing for the onclick event of the button. So, do I
>> >need to manually enter the "SelectedIndexChanged"

event
>> in
>> >the html for the listbox?
>> >
>> ><asp:listbox id="lstProducts" style="Z-INDEX: 101;

LEFT:
>> >48px; POSITION: absolute; TOP: 80px"runat="server"
>> >Height="192px" Width="400px"></asp:listbox>
>> >
>> >Thanks,
>> >Steve
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
Karl
Guest
Posts: n/a
 
      08-20-2004
The button would be the same...it's a VB.Net thing, not a specific control
thing. It has to do with how to hook up events.

If you go to your codebehind page and expand the section which was created
by the designer. Chances are you'll see all the controls you use in your
aspx file. They'll already have the WithEvents on them, and look something
like:

Protected WithEvents lst1 as System.Web.UI.WebControls.ListBox
Protected WithEvents ....

If they aren't there, make sure to check closely, you can add them.

One that's done, it looks like this:

Private Sub Doesn_not_Matter_what_Name(...) Handles
lst1.SelectedIndexChanged
....
End Sub


"Steve" <(E-Mail Removed)> wrote in message
news:264601c48659$40bc9a90$(E-Mail Removed)...
> Thanks for the explanation. I took a class in asp.net
> last spring (short course). Now I have to start using
> it. May I ask what the WithEvents version of your
> explanation would look like?
>
> I noticed that I didn't have to deal with this with the
> button. I am guessing the button has different rules
> than a listbox. So for WithEvents
>
>
> Dim lst1 As ListBox1 WithEvents
>
> ...
>
> Private Sub ListBox1_SelectedIndexChanged(...)
> ...
> End Sub
>
> something like this? I already have something that
> works, but only in the blind. Just trying to grasp some
> understanding.
>
> Thanks for your reply,
> Steve
>
>
> >-----Original Message-----
> >What you are doing is standard convention. Perhaps they

> made the default to
> >false because (a) it's how things have worked in the

> past (b) there is a
> >performance penalty (you are hitting the server again),

> so they want you to
> >consciouly acknowledge that this is what you are doing.
> >
> >You can keep the sub private, and remove the
> >OnSelectedIndexChanged="lstProducts_SelectedIndex Changed"

> from the tag and
> >instead declare the lstProducts in your codebehind with

> the "WithEvents"
> >keyword and declare your sub something like
> >
> >private sub...() Handles lstProducts.SelectedIndexChange
> >
> >Differences are trivial so consider it more a matter of

> preference.
> >
> >Karl
> >
> >"Steve" <(E-Mail Removed)> wrote in

> message
> >news:94f301c48641$e6bf7600$(E-Mail Removed)...
> >> Well I modified my listbox tag (which now works) as

> follows
> >>
> >> <asp:listbox id="lstProducts" style="Z-INDEX: 101;

> LEFT:
> >> 48px; POSITION: absolute; TOP: 80px"

> autopostback="True"
> >>

> OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
> >> runat="server" Height="192px"

> Width="400px"></asp:listbox>
> >>
> >> I added autopostback="True" and then called the sub
> >>

> OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
> >>
> >> But I had to remove the Private keyword from the sub.
> >> Question: is it standard convention then to use
> >> autopostback="true" to invoke subs for aspx? this did
> >> not seem real intuitive to me.
> >>
> >> Thanks,
> >> Steve
> >>
> >> >-----Original Message-----
> >> >Hi,
> >> >
> >> >I open up a webform (vb.net) and populate a listbox
> >> >control on the Page load event. If I click on

> (select)
> >> >and item from the listbox I want to write the value of
> >> the
> >> >selected item to a label control. Nothing happens.

> But
> >> >when I click a button (which contains same code to

> write
> >> >to label) I get the value of the selected item in the
> >> >Label.
> >> >
> >> >I looked at the html portion of my webform and don't

> see
> >> a
> >> >listing for the onclick event of the button. So, do I
> >> >need to manually enter the "SelectedIndexChanged"

> event
> >> in
> >> >the html for the listbox?
> >> >
> >> ><asp:listbox id="lstProducts" style="Z-INDEX: 101;

> LEFT:
> >> >48px; POSITION: absolute; TOP: 80px"runat="server"
> >> >Height="192px" Width="400px"></asp:listbox>
> >> >
> >> >Thanks,
> >> >Steve
> >> >.
> >> >

> >
> >
> >.
> >



 
Reply With Quote
 
Steve
Guest
Posts: n/a
 
      08-20-2004
Thanks. I get it now. I forgot about that region
designer thing. Now I have a little more understanding of
what I am doing. I don't like "just getting lucky". Luck
usually runs out (quickly for me .

Thanks for your help

>-----Original Message-----
>The button would be the same...it's a VB.Net thing, not a

specific control
>thing. It has to do with how to hook up events.
>
>If you go to your codebehind page and expand the section

which was created
>by the designer. Chances are you'll see all the controls

you use in your
>aspx file. They'll already have the WithEvents on them,

and look something
>like:
>
>Protected WithEvents lst1 as

System.Web.UI.WebControls.ListBox
>Protected WithEvents ....
>
>If they aren't there, make sure to check closely, you can

add them.
>
>One that's done, it looks like this:
>
>Private Sub Doesn_not_Matter_what_Name(...) Handles
>lst1.SelectedIndexChanged
>....
>End Sub
>
>
>"Steve" <(E-Mail Removed)> wrote in

message
>news:264601c48659$40bc9a90$(E-Mail Removed)...
>> Thanks for the explanation. I took a class in asp.net
>> last spring (short course). Now I have to start using
>> it. May I ask what the WithEvents version of your
>> explanation would look like?
>>
>> I noticed that I didn't have to deal with this with the
>> button. I am guessing the button has different rules
>> than a listbox. So for WithEvents
>>
>>
>> Dim lst1 As ListBox1 WithEvents
>>
>> ...
>>
>> Private Sub ListBox1_SelectedIndexChanged(...)
>> ...
>> End Sub
>>
>> something like this? I already have something that
>> works, but only in the blind. Just trying to grasp some
>> understanding.
>>
>> Thanks for your reply,
>> Steve
>>
>>
>> >-----Original Message-----
>> >What you are doing is standard convention. Perhaps

they
>> made the default to
>> >false because (a) it's how things have worked in the

>> past (b) there is a
>> >performance penalty (you are hitting the server again),

>> so they want you to
>> >consciouly acknowledge that this is what you are doing.
>> >
>> >You can keep the sub private, and remove the

>>

>OnSelectedIndexChanged="lstProducts_SelectedIndex Changed"
>> from the tag and
>> >instead declare the lstProducts in your codebehind with

>> the "WithEvents"
>> >keyword and declare your sub something like
>> >
>> >private sub...() Handles

lstProducts.SelectedIndexChange
>> >
>> >Differences are trivial so consider it more a matter of

>> preference.
>> >
>> >Karl
>> >
>> >"Steve" <(E-Mail Removed)> wrote in

>> message
>> >news:94f301c48641$e6bf7600$(E-Mail Removed)...
>> >> Well I modified my listbox tag (which now works) as

>> follows
>> >>
>> >> <asp:listbox id="lstProducts" style="Z-INDEX: 101;

>> LEFT:
>> >> 48px; POSITION: absolute; TOP: 80px"

>> autopostback="True"
>> >>

>>

OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
>> >> runat="server" Height="192px"

>> Width="400px"></asp:listbox>
>> >>
>> >> I added autopostback="True" and then called the

sub
>> >>

>>

OnSelectedIndexChanged="lstProducts_SelectedIndexC hanged"
>> >>
>> >> But I had to remove the Private keyword from the sub.
>> >> Question: is it standard convention then to use
>> >> autopostback="true" to invoke subs for aspx? this

did
>> >> not seem real intuitive to me.
>> >>
>> >> Thanks,
>> >> Steve
>> >>
>> >> >-----Original Message-----
>> >> >Hi,
>> >> >
>> >> >I open up a webform (vb.net) and populate a listbox
>> >> >control on the Page load event. If I click on

>> (select)
>> >> >and item from the listbox I want to write the value

of
>> >> the
>> >> >selected item to a label control. Nothing happens.

>> But
>> >> >when I click a button (which contains same code to

>> write
>> >> >to label) I get the value of the selected item in

the
>> >> >Label.
>> >> >
>> >> >I looked at the html portion of my webform and don't

>> see
>> >> a
>> >> >listing for the onclick event of the button. So,

do I
>> >> >need to manually enter the "SelectedIndexChanged"

>> event
>> >> in
>> >> >the html for the listbox?
>> >> >
>> >> ><asp:listbox id="lstProducts" style="Z-INDEX: 101;

>> LEFT:
>> >> >48px; POSITION: absolute; TOP: 80px"runat="server"
>> >> >Height="192px" Width="400px"></asp:listbox>
>> >> >
>> >> >Thanks,
>> >> >Steve
>> >> >.
>> >> >
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re module: Nothing to repeat, but no sre_constants.error: nothing torepeat ? Devin Jeanpierre Python 2 02-14-2012 01:33 PM
click click click Andy Morrison Computer Support 7 12-20-2007 06:50 AM
Any way to have a ListBox with nothing selected? MattB ASP .Net 7 07-22-2004 11:23 PM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
click listbox and refresh another listbox DC Gringo ASP .Net Building Controls 0 04-06-2004 02:13 AM



Advertisments