![]() |
|
|
|||||||
![]() |
ASP Net - Listbox item added with client scripts not submitting with ASP:Listbox |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Help
I have a ASP:Listbox on a form. My page Adds items to this this via Client-Side Script only. Such as... var vObj_TargetElement = document.getElementById("_PageTemplate_innerHolder _oASP_Lbx_Invoice"); var vObj_SourceElement = document.getElementById("oHTML_Tbx_Invoice"); var vInt_OptionTotal = vObj_TargetElement.length++; vObj_TargetElement.options[vInt_OptionTotal].value = Trim(vObj_SourceElement.value); vObj_TargetElement.options[vInt_OptionTotal].text = Trim(vObj_SourceElement.value); When the form is submitted, these new items are not submitted within the LISTBOX. Server-Side code such as ... Response.Write(oASP_Lbx_Invoice.Items.Count.ToStri ng) Returns 0 (zero) Any ideas how to solve this ?? Thanks. Simon [Remove the NOSPAM if replying by email] Simon Prince |
|
|
|
|
#2 |
|
Posts: n/a
|
"Simon Prince" <> wrote in message news:cl0ohg$qh7$1$... > Help > > I have a ASP:Listbox on a form. My page Adds items to this this via > Client-Side Script only. > Such as... > > var vObj_TargetElement = > document.getElementById("_PageTemplate_innerHolder _oASP_Lbx_Invoice"); > var vObj_SourceElement = document.getElementById("oHTML_Tbx_Invoice"); > var vInt_OptionTotal = vObj_TargetElement.length++; > vObj_TargetElement.options[vInt_OptionTotal].value = > Trim(vObj_SourceElement.value); > vObj_TargetElement.options[vInt_OptionTotal].text = > Trim(vObj_SourceElement.value); > > > When the form is submitted, these new items are not submitted within the > LISTBOX. > > Server-Side code such as ... > Response.Write(oASP_Lbx_Invoice.Items.Count.ToStri ng) > > Returns 0 (zero) > > Any ideas how to solve this ?? > > Thanks. > > Simon > > [Remove the NOSPAM if replying by email] > It looks as though a listbox is read only as far as once it goes down to the client as html. The server control does not look at what happens to the list box once it leaves the server. When you go back to the server it uses the server version to reload the box. I messed around with the code you posted and that seems to be what is happening. It seems to be a one way street. Is there any way to have the listbox do a postback to update it? jjardine |
|
|
|
#3 |
|
Posts: n/a
|
The way it is normally done is through a hidden field. Whenever your
client-side script runs to add the value to the list, add it to the hidden field as well. On postback repopulate the listbox with the values from the hidden field. You need to be careful because, if I remember correctly, the listbox will retain whatever values were in it when it was originally sent to the client. So either handle this case or always have the hidden field represent values that were added during the current client session (prior to postback). I have seen a custom control somewhere that did just what you wanted but I can't remember where. You could try Code Project or Code Guru. Michael Taylor, MCP - 10/19/04 "Simon Prince" wrote: > Help > > I have a ASP:Listbox on a form. My page Adds items to this this via > Client-Side Script only. > Such as... > > var vObj_TargetElement = > document.getElementById("_PageTemplate_innerHolder _oASP_Lbx_Invoice"); > var vObj_SourceElement = document.getElementById("oHTML_Tbx_Invoice"); > var vInt_OptionTotal = vObj_TargetElement.length++; > vObj_TargetElement.options[vInt_OptionTotal].value = > Trim(vObj_SourceElement.value); > vObj_TargetElement.options[vInt_OptionTotal].text = > Trim(vObj_SourceElement.value); > > > When the form is submitted, these new items are not submitted within the > LISTBOX. > > Server-Side code such as ... > Response.Write(oASP_Lbx_Invoice.Items.Count.ToStri ng) > > Returns 0 (zero) > > Any ideas how to solve this ?? > > Thanks. > > Simon > > [Remove the NOSPAM if replying by email] > > > =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?= |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to pass selected item from listbox of one form to text box of other form | chintan | Software | 0 | 12-19-2007 11:38 AM |