By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,990 Members | 1,741 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,990 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.