ASP.Net Controls and Javascript

G

Guest

I used some javascript to move entries from one ASP.Net ListBox control to
another ASP.NET Listbox control.

On the client side all appears fine, but when I click a button which causes
the page to go back to the server, the items which I placed in the ListBox
control do not show up in the ListBox.Items.Count property. Does this mean
that I can not use javascript to move values from one ASP.NET control to
another ASP.NET control? I find this hard to believe, so there must be
something I must have to do that I am not doing, but what would that be?

Any assistance would be greatly appreciated.
 
J

John Saunders

Jim Heavey said:
I used some javascript to move entries from one ASP.Net ListBox control to
another ASP.NET Listbox control.

On the client side all appears fine, but when I click a button which
causes
the page to go back to the server, the items which I placed in the ListBox
control do not show up in the ListBox.Items.Count property. Does this
mean
that I can not use javascript to move values from one ASP.NET control to
another ASP.NET control? I find this hard to believe, so there must be
something I must have to do that I am not doing, but what would that be?

Any assistance would be greatly appreciated.

Jim,

Client-side controls only post back their values, not their details. You can
do whatever you like with the DOM, but if it doesn't change the Value of the
control, nothing will go back to the server.

In order to do what you want, you would have to store your changes somewhere
that will get back to the server. For instance, in a hidden input field. The
server could then see the changes and add the changes to your listbox on the
server side.

John Saunders
 
G

Guest

I am adding items to an ASP.NET Control and that control goes back to the
server, so I am confused as to why my entries do not appear. The ASP.NET
control just renders to an <Select HTML object. If in my script I an
referencing this object then when that object get back to the server, those
items s/b there?

So what am I missing?
 
J

John Saunders

Jim Heavey said:
I am adding items to an ASP.NET Control and that control goes back to the
server, so I am confused as to why my entries do not appear. The ASP.NET
control just renders to an <Select HTML object. If in my script I an
referencing this object then when that object get back to the server,
those
items s/b there?

So what am I missing?

You're missing the fact that you are adding items to the <select> control on
the client side. HTML does not post these items back to the server. This
isn't an ASP.NET issue, it's a basic HTML issue.

The only changes you can make on the client which will be sent back to the
server are changes to the value property of the controls. That's all that's
sent back in a POST. The web browser doesn't send the entire DOM back to the
server!

John Saunders
 
A

Alex Homer

But you can get the items in the list from the Request.Form or
Request.QueryString collection...
 
J

John Saunders

Alex Homer said:
But you can get the items in the list from the Request.Form or
Request.QueryString collection...

No you can't! What makes you think you can? Have you seen them? Turn on page
tracing and look to see if these are sent to the server. They're not sent!

Think about it. How much of the web page should be sent back to the server?
Whatever changed?

John Saunders
 
S

Stibbs

Quick note about this simple issue,

The problem is that the person is not fully understanding the html post
item and if the item doesn’t change any value is returned to the server.

I had along time ago thought that learning Interdev 6 would solve all my
application creation issues, but after taking a expensive course in
Interdev I only discovered that, if I did not write the ASP and HTML
myself, I did not know what was going-on on the page.

This is the case here, the items must be presented and passed correctly
and only by knowing all the issues can you debug the problems quickly
and efficiently.

I do not mean to belittle anyone’s abilities, knowing these software
programs is difficult at best, just that, (to me anyway) knowing and
writing the software by hand is better that using the fancy tools of
ASP.NET.
 
J

Jo Blow

I agree, my programmers use web matrix, notepad or (preferably) an old
version of (belive it or not) Homesite

Visual Studio tricks you and you never know (or control) what is really
going on. I agree it's a fantastic tool, but sometimes if you don't want to
fit into Microsoft's Box of how navigation should work then you just have to
do it yourself.

But there is an awfull lot to learn.

Boldy
 
A

Antony Stephen

Jim,
Am facing the same problem. can you please forward the solution if u
got it..
thank you in advance.
Antony.
 
Joined
May 27, 2007
Messages
1
Reaction score
0
Simple Answer

Hi All,

Just a simple answer to this problem (albeit a few years late on when it was reported) - simply have a javascript function select all the items in the listbox when the button is pressed, it then posts back the values to the aspx page.

Hope this helps a few people out!
- Will

index.aspx.vb file (add to the page_load function)
Button3.Attributes.Add("onclick", "javascript:selectallusers();")

index.aspx file
<asp:Button ID="Button3" runat="server" Text="Press Me" />

function selectallusers() {
for(i=0; i<document.form1.ListBox1.options.length; i++)
document.form1.ListBox1.options.selected = true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top