472,969 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 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 2583
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...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.