script question

J

Jeff User

HI all.
I am using .NET1.1 , C#.
For the most part I am using server side C# code for many pages and
have been coming along OK. But now, I would like to populate a listbox
on the client side (if possible) based on the user selection of an
item in a dropDownList .

I found this example and tryed it but the value added to the listBox
does not display. However, if I then postback for any other reason at
all (including click a button with no function attached to it) then
the new value added to the list appears.

aspx page <head> section:
<script language="C#" runat="server">
void oIndexChanged (Object sender, EventArgs e)
{
lbPrivileges.Items.Add("New_Item");
}
</script>

<asp:dropdownlist id="ddlDbObjects" style="Z-INDEX: blah blah blah
runat="server" OnSelectedIndexChanged="oIndexChanged">

autopostback for dropDownList is set to false.

1) Does this script run on the client side but result does not appear
or doesn't it even run?

2) This example code showed using C# language scipt. Would java script
be better and of so, what are the reasons for using one over the other
- C# code or java script - on client side.

3) What do I need to do accomplish my goal? Fix the above or something
entirely different?

Thanks
Jeff
 
P

Peter Rilling

There is no client script there. It all runs on the server, which would
explain why it only appears after a postback.

Just because code is in the HTML page, does not mean it runs on the client.
Also, whenever you have a runat=server, the attached events are processed on
the server, not client. Also, IE cannot run C# code.

Now, you can use JavaScript, but then during a postback, your values would
disappear because the server would not be able to map that new value you
added to some HTML on the page. For things like this, it is usually best to
do a postback and use something like SmartNavigation to prevent noticeable
refreshes of the page.
 
J

Jeff User

Peter
Got it. Thanks!
That clears up a lot of questions for me.
Is there any good information in particlular that you might recommend
for me to get started with SmartNavigation?

Thanks again
Jeff
 

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

Top