HTML ListBox and a .aspx page...

P

Pai

Hello there,

In a .aspx page I have a HTML Select Control... a listbox and a aspx
server control a button.

using javascript I add items into it the list box as follows:

var myNewOption = new Option("test1","test1");
document.Form1.Select2.options[0] = myNewOption;

var myNewOption = new Option("test2","test2");
document.Form1.Select2.options[1] = myNewOption;

now when i click on the aspx server control the button, i need to get
the count of the number of options in the listbox.

I use the following code in the code behind section of my .aspx page.


private void btnCreateSite_Click(object sender, System.EventArgs e)
{
Response.Write ("Count:"+Select2.Items.Count);
}

but the count is always zero....

how do i get the count for the number of the list items and the value
of the items whcih I have populated in the listbox using javascript in
my code behind.

Any suggestion or help....

Kind Regards,
Srikanth Pai
 
T

Teemu Keiski

By default client-side changes are not persisted to Items collection of the
corresponding DDL control.

By default it is so as ViewState is used to keep track of changes that
have been notified at server-side (cause postback in other words) as
otherwise the ASP.NET is not aware that any changes have occurred. But as I
said it is only by default, such control can be done and Andy Smith has
developed a first-class control to overcome the problem.

See:
http://www.metabuilders.com/Tools/DynamicListBox.aspx

--
Teemu Keiski
MCP, Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com
 

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
474,076
Messages
2,570,565
Members
47,201
Latest member
IvyTeeter

Latest Threads

Top