473,385 Members | 1,445 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,385 software developers and data experts.

Mixing Server and Client Code

I am having big time problems seperating the two mention in subject line.

I want to create a list of items (listbox or select) from a button click (on
the server). The button click will ensure that all data required for
viewing the page is within the page and after that selecting items from the
table should cause client processing to modify the look of the page.

The server code is easy. I access data on the server and add it to the the
items collection of the listbox. Now logically I want to switch to client
processing with JavaScript. The problem follows:

If I use a ListBox (<asp:ListBox) then how would I capture a selection
change so that I can process the clientside code? I would need the text of
the selected item as well.

If I use a Select (straight HTML) then how does the server fill the HTML
listbox?

I also am very confused about how Intellisence seems to know about controls
but runtime does not. I have another control defined as <EMBED id="Player"
.... When I am inputing client JavaScript I get full Intellisence help for
this name (Player) but when I call the function which references the control
I get runtime errors (I have script debugging set on) indicating that the
control Player does not exist.
Nov 18 '05 #1
1 1085
I think this is what you're trying to do...

Code-Behind snippet:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then

'simulate loading first time in from your database query
Dim alText As New ArrayList
Dim alVals As New ArrayList
alText.Add("Item One")
alVals.Add("1")
alText.Add("Item Two")
alVals.Add("2")
alText.Add("Item Three")
alVals.Add("3")

For i As Integer = 0 To alText.Count - 1
myListBox.Items.Add(New ListItem(alText(i),
alVals(i)))
Next

myListBox.Attributes.Add("onchange", "test(this)")
End If
End Sub

HTML snippet:

<HEAD>
<title>WebForm1</title>
<script language="javascript">
function test(select) {
var i = select.selectedIndex
var opts = select.options
alert(opts[i].text + " has a value of " +
opts[i].value)
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:ListBox id="myListBox" runat="server"></asp:ListBox>
<br>
<input type=submit>
</form>
</body>
Nov 18 '05 #2

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

Similar topics

1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
9
by: Chuck Bowling | last post by:
I have an ASP.NET page with code behind that i'm trying to get to launch a modeless windows form on the IIS server. I tried creating a windows form in the web application project and adding a...
5
by: Shawn Repphan | last post by:
I have a webform with about 20 html textboxes and checkboxes. I am using ICallbackEventHandler to page through these successfully. But I need to be able to accept changes from these fields. How can...
10
by: Ben | last post by:
Hi, I made an application in classic asp (reservation of books and video stuffs for students) and want to migrate to asp.net. The user has to chose a date, then pushung on a submit button. The...
2
by: Richard | last post by:
Hi All, I just picked up an ASP.NET "Mortgage Calculator" example with code-behind from Prosise's 2002 "Programming Microsoft.NET". Works great. User enters a few values, clicks button, and...
28
by: ziman137 | last post by:
Hello all, I have a question and am seeking for some advice. I am currently working to implement an algorithmic library. Because the performance is the most important factor in later...
7
by: =?Utf-8?B?am9uZWZlcg==?= | last post by:
I'm hoping this is a classic question, but the answer to it would help me with a lot of things. As you can see below, this code will never display the "Getting data...." text in the lblCheck -...
1
by: Yonin | last post by:
Hi all, A question about hybrid systems: Any idea how I can make my JAVA server talk with my MMI client, that must be written in C#? Thank's. Yoni
14
by: Tom Louchbaum | last post by:
Is there someway to tell who has the *.DB open on a network?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.