473,378 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

populating dropdownlist (asp.net server ctrl) from clientside jscr

Hello together,

I tried to find out about populating an asp.net server control (a
dropdownlist) from the clientside jscript, but I didn't find a solution up
to now.
I cannot use a html dropdownlist, because a database query in codebehind has
to be done, when a new listItem is selected. So, I need to use a
servercontrol dropdownlist.

Now to my problem:
I have two dropdownlists in use. One of them should show listItems that are
dependent on the selection of the other one. I know that I need to use the
clientside onchange() Event on the dropdownlistbox that decides what has to
be shown in the other dropdownlist, because no postback should occur for this.
The C# syntax, that is used in codebehind, doesn't work, JScript gives me an
error that the object doesn't support this method.
I can set the text and state of servercontrols like textBoxes and checkBoxes
from clientside jscript with document.Form1.TextBox1..., so it should also be
possible to do this with a dropdownlist too, shouldn't it?

I tried it with Ajax.NET, but when I called a serverside function that
should manipulate the dropdownlist, a nullpointerexception occurs, because
all the instances of the serverside controls are "undefined" (I saw it in the
debugger). I've no explanation for this, as they are created on page_Load. So
I cancelled my efforts introducing Ajax into this. As the project is nearly
finished, I would like to avoid using Ajax for the dropdownlist stuff.

I hope somebody can help

Thanks in advance

RFS666
Nov 19 '05 #1
3 2603
var i = document.forms[0].DropDownListName.length
document.forms[0].DropDownListName.options[i] = new Option('new text','new
value');

HTH

"RFS666" wrote:
Hello together,

I tried to find out about populating an asp.net server control (a
dropdownlist) from the clientside jscript, but I didn't find a solution up
to now.
I cannot use a html dropdownlist, because a database query in codebehind has
to be done, when a new listItem is selected. So, I need to use a
servercontrol dropdownlist.

Now to my problem:
I have two dropdownlists in use. One of them should show listItems that are
dependent on the selection of the other one. I know that I need to use the
clientside onchange() Event on the dropdownlistbox that decides what has to
be shown in the other dropdownlist, because no postback should occur for this.
The C# syntax, that is used in codebehind, doesn't work, JScript gives me an
error that the object doesn't support this method.
I can set the text and state of servercontrols like textBoxes and checkBoxes
from clientside jscript with document.Form1.TextBox1..., so it should also be
possible to do this with a dropdownlist too, shouldn't it?

I tried it with Ajax.NET, but when I called a serverside function that
should manipulate the dropdownlist, a nullpointerexception occurs, because
all the instances of the serverside controls are "undefined" (I saw it in the
debugger). I've no explanation for this, as they are created on page_Load. So
I cancelled my efforts introducing Ajax into this. As the project is nearly
finished, I would like to avoid using Ajax for the dropdownlist stuff.

I hope somebody can help

Thanks in advance

RFS666

Nov 19 '05 #2
First, when the browser sees the control, it is no longer a server-side
control, but just HTML. You can do whatever you can with the control, but
it needs to be through JavaScript with JS syntax and commands. Take a look
at the
http://msdn.microsoft.com/workshop/a...asp?frame=true
for information about the those lists from the IE perspective.

In order for the server objects to be populated, you must to some form of
postback, otherwise the server does not know what to do. You might consider
using SmartNavigation and performing postbacks without the screen flicker.
"RFS666" <RF****@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hello together,

I tried to find out about populating an asp.net server control (a
dropdownlist) from the clientside jscript, but I didn't find a solution
up
to now.
I cannot use a html dropdownlist, because a database query in codebehind
has
to be done, when a new listItem is selected. So, I need to use a
servercontrol dropdownlist.

Now to my problem:
I have two dropdownlists in use. One of them should show listItems that
are
dependent on the selection of the other one. I know that I need to use the
clientside onchange() Event on the dropdownlistbox that decides what has
to
be shown in the other dropdownlist, because no postback should occur for
this.
The C# syntax, that is used in codebehind, doesn't work, JScript gives me
an
error that the object doesn't support this method.
I can set the text and state of servercontrols like textBoxes and
checkBoxes
from clientside jscript with document.Form1.TextBox1..., so it should also
be
possible to do this with a dropdownlist too, shouldn't it?

I tried it with Ajax.NET, but when I called a serverside function that
should manipulate the dropdownlist, a nullpointerexception occurs, because
all the instances of the serverside controls are "undefined" (I saw it in
the
debugger). I've no explanation for this, as they are created on page_Load.
So
I cancelled my efforts introducing Ajax into this. As the project is
nearly
finished, I would like to avoid using Ajax for the dropdownlist stuff.

I hope somebody can help

Thanks in advance

RFS666

Nov 19 '05 #3
you need to lean the browser dom to do client script (or ajax). also if you
change the entires in a list client side, you need to send this info to the
server somehow (usually a hidden field), as the browser only posts pack the
selected value of a dropdown. you shoudl go to the bookstore and pickup a
book on javascript.

-- bruce (sqlwork.com)

"RFS666" <RF****@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com...
Hello together,

I tried to find out about populating an asp.net server control (a
dropdownlist) from the clientside jscript, but I didn't find a solution
up
to now.
I cannot use a html dropdownlist, because a database query in codebehind
has
to be done, when a new listItem is selected. So, I need to use a
servercontrol dropdownlist.

Now to my problem:
I have two dropdownlists in use. One of them should show listItems that
are
dependent on the selection of the other one. I know that I need to use the
clientside onchange() Event on the dropdownlistbox that decides what has
to
be shown in the other dropdownlist, because no postback should occur for
this.
The C# syntax, that is used in codebehind, doesn't work, JScript gives me
an
error that the object doesn't support this method.
I can set the text and state of servercontrols like textBoxes and
checkBoxes
from clientside jscript with document.Form1.TextBox1..., so it should also
be
possible to do this with a dropdownlist too, shouldn't it?

I tried it with Ajax.NET, but when I called a serverside function that
should manipulate the dropdownlist, a nullpointerexception occurs, because
all the instances of the serverside controls are "undefined" (I saw it in
the
debugger). I've no explanation for this, as they are created on page_Load.
So
I cancelled my efforts introducing Ajax into this. As the project is
nearly
finished, I would like to avoid using Ajax for the dropdownlist stuff.

I hope somebody can help

Thanks in advance

RFS666

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marius | last post by:
Hi all, I need an asp:dropdownlist on a webform that is databound to a dataset. This works fine and returns the data to populate my dropdownlist. In the DB I only have valid data, but I need a...
2
by: amessimon | last post by:
I need to display a drop down list which holds up to 250 listitems. I'd like to create this programmatically rather than have to hardcode it into the page. For example <asp:DropDownList...
1
by: Urmal Patel via .NET 247 | last post by:
I have problem with asp:Dropdownlist. I have a dropdownlist control in Page1.aspx and I want to assign value and Text to dropdown list form Page2.aspx from java script function. I am able to assign...
8
by: gv | last post by:
Ok, Hi all, new to asp.net. Simple question with web forms I have a Dropdownlist and a listbox, I want to click on and item in the dropdownlist and show items in listbox. that simple I...
1
by: Mike P | last post by:
I am populating a drop down column in a datagrid on page load. Here is my code : <asp:TemplateColumn> <ItemTemplate> <asp:DropDownList ID="ddlUserName" Font-Name="Verdana" Font-Size="8pt"...
0
by: Mike P | last post by:
I know how to populate a dropdown list in a gridview in edit mode when the dropdown is populated by a datasource (see below eg 1), but how do you populate the dropdown when the dropdown is...
3
by: John Kotuby | last post by:
Hi all... I am trying to do a simple thing and maybe am missing something elementary. I have created a Javascript function at the top of a page which is meant to enable editing of an HTML input...
2
by: John Kotuby | last post by:
Hi all, In ASP.NET 2.0 and VB.NET, I am trying to get the OnSelectedIndexChanged event to fire a Javascript function. There is no OnClientClick event for that control. When I try something...
2
by: Moiseszaragoza | last post by:
I am not sure if this goes in here ot the ASP forum I have been trying to get some simple AJAX on my site but its not going so well I am not sure what my problems is what i am trying to do is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.