[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

Cant use client-side JavaScript for Select ?

cellbert

1/9/2003 6:56:00 AM

I have a <Select ... runat="server"> on the page, named
selOne. On initial Page_Load, I populate it with one item
in code. This displays fine. In client-side javascript,
responding to a button on the page, I add some more items
to it. On post-back of the page, I do nothing to this
Select element, in fact I do nothing anywhere on the page,
but what I get back in the variable selOne is the initial
single element, as if my client-side Javascript had no
effect. I've checked with client-side Javascript alerts
that my additional items were really added (ie, on the
client, selOne.innerHTML displays them). Any ideas?
Thanks...
4 Answers

Victor Garcia Aprea [MVP]

1/9/2003 8:57:00 AM

0

Hi Cellbert,

Any modifications you make to your <select> at client-side (adding, removing
items, etc) won't be automatically posted to & parsed by the server. You
will need to write some code to do that, basically posting the entire item
list to the server (ie. in a hidden form field), parsing it there and
filling the Items collection.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.


"cellbert" <hkoster@nyc.rr.com> wrote in message
news:25e201c2b7a3$dda64990$89f82ecf@TK2MSFTNGXA01...
> I have a <Select ... runat="server"> on the page, named
> selOne. On initial Page_Load, I populate it with one item
> in code. This displays fine. In client-side javascript,
> responding to a button on the page, I add some more items
> to it. On post-back of the page, I do nothing to this
> Select element, in fact I do nothing anywhere on the page,
> but what I get back in the variable selOne is the initial
> single element, as if my client-side Javascript had no
> effect. I've checked with client-side Javascript alerts
> that my additional items were really added (ie, on the
> client, selOne.innerHTML displays them). Any ideas?
> Thanks...


Jim Ross [MVP]

1/9/2003 4:00:00 PM

0

Andy Smith has a listbox control that is able to persist client-side
changes to its Items collection. It is free and comes with source code
so that you can see how he did it. Here's the URL
http://metabuilders.com/Tools/DynamicLi...

"cellbert" <hkoster@nyc.rr.com> wrote:

>I have a <Select ... runat="server"> on the page, named
>selOne. On initial Page_Load, I populate it with one item
>in code. This displays fine. In client-side javascript,
>responding to a button on the page, I add some more items
>to it. On post-back of the page, I do nothing to this
>Select element, in fact I do nothing anywhere on the page,
>but what I get back in the variable selOne is the initial
>single element, as if my client-side Javascript had no
>effect.
Jim Ross
MS MVP [ASP.NET][VC/MFC emeritus]

To send email, change 'lotsofspamthroughhere' to 'msn' but please ask all questions in the newsgroups, not via private mail

cellbert

1/9/2003 4:52:00 PM

0

Jim, Victor - thank you both for excellent suggestions
maintaining the hidden field works fine (while I check
that URL) -- Howard

Eddy

1/17/2003 3:57:00 PM

0

Hi Cellbert,

What you need to do is make sure that when you're posting
you're form back to the server, that all your options in
the listbox are selected. So before posting run a
javascript function which loops thru the option elements
and select then one by one.

Greetz,
Eddy

>-----Original Message-----
>I have a <Select ... runat="server"> on the page, named
>selOne. On initial Page_Load, I populate it with one
item
>in code. This displays fine. In client-side javascript,
>responding to a button on the page, I add some more
items
>to it. On post-back of the page, I do nothing to this
>Select element, in fact I do nothing anywhere on the
page,
>but what I get back in the variable selOne is the initial
>single element, as if my client-side Javascript had no
>effect. I've checked with client-side Javascript alerts
>that my additional items were really added (ie, on the
>client, selOne.innerHTML displays them). Any ideas?
>Thanks...
>.
>