Friday, March 16, 2012

ListBox Event - How Do I

I have a listbox, with a code behind on SelectedIndexChanged
This works well, except for one condition.
On returning to the listbox after PostBack, the previous selection is
still highlighted. This is how I want it as it tells the user, which
was his previous selection.
The problem i have, is that if the user reselects the previous
selection, which can be done for a valid reason, the
SelectedIndexChanged does not get called.
What property do I need to test, for in effect the selection click
event, rather than the indexchanged event, as I very much want to
retain the Previous Selected item.
I hope this is clear.
In other words how can I trap the selection, rather than the index
changing.
Thanks for all your previous help in the past - I am getting there - be
it rather slowly.
RichardAre you using AutoEventWireup '
If yes, then there are no other events...
But u can try catching the event in Javascript and then firing the
event from the script...
Again , I am not sure whether JS catches the event as not done in
ASP.NET....
U can give it a try...
Sorry to be so dumb, but what is AutoEventWireup - that is a new one
for my learning curve.
I am trying to avoid javascript at any event I am hoping my app will be
accessible, from a mobile browser and not all support javascript.
Thanks - Richard
That's how you trap the selection, by the index changing. That is only
wording, it's value, index, item all that changes.
Now, if the SelectedIndexChanged isn't firing when the user selects a
new item (it won't fire if the selection doesn't change between posts
to the server) then 1 of 2 things are happening. 1 the item hasn't
changed or 2, you are rebinding the list box on every post - which you
shouldn't do. Only rebind on the first post (Not IsPostBack) and
whenever the data source of the list box has changed.
-Rick
I will investigate further - I am probably binding on every postback,
as I am still trying to work out the event sequence for posting back.
Having progressed through all the getting started videos, it is
becoming more obvious that although all the goodie controls are nice,
when they come to real world datadriven applications, one ends up using
the lowest level control available.
As an aside can you recommend any article which differentiates, between
all the sqlClient classes. As I am getting as to which is the
best approach, bearing in mind my desire to have efficient access and
avoid unnecessary trips to the server . ( A long time ago an assembly
language programmer - so efficiency is tattooed on my forehead)
Thanks again - Richard
If the index isn't changing, I was assume you'd have to catch the onclick
event from the client-side and initiate the postback from there.
"mosscliffe" <page77.office@.googlemail.com> wrote in message
news:1147267827.035431.49980@.i40g2000cwc.googlegroups.com...
>I have a listbox, with a code behind on SelectedIndexChanged
> This works well, except for one condition.
> On returning to the listbox after PostBack, the previous selection is
> still highlighted. This is how I want it as it tells the user, which
> was his previous selection.
> The problem i have, is that if the user reselects the previous
> selection, which can be done for a valid reason, the
> SelectedIndexChanged does not get called.
> What property do I need to test, for in effect the selection click
> event, rather than the indexchanged event, as I very much want to
> retain the Previous Selected item.
> I hope this is clear.
> In other words how can I trap the selection, rather than the index
> changing.
> Thanks for all your previous help in the past - I am getting there - be
> it rather slowly.
> Richard
>

0 comments:

Post a Comment