Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Mixing Server and Client Code

Thread Tools

Mixing Server and Client Code

Lloyd Sheen
Posts: n/a
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

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.

Reply With Quote
Posts: n/a
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")
alText.Add("Item Two")
alText.Add("Item Three")

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

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

HTML snippet:

<script language="javascript">
function test(select) {
var i = select.selectedIndex
var opts = select.options
alert(opts[i].text + " has a value of " +
<form id="Form1" method="post" runat="server">
<asp:ListBox id="myListBox" runat="server"></asp:ListBox>
<input type=submit>
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Client-side mixing for VOIP conferences VOIP 0 09-21-2006 10:51 PM
Mixing client-side and server-side processing: How? Richard ASP .Net 2 05-12-2006 12:56 PM
Mixing server and client controls Shawn Repphan ASP .Net 5 01-20-2006 12:08 AM
Server to server = Server client to server? - Java 2 07-29-2005 10:46 PM
Mixing C library code and callbacks with C++ Classes C++ 4 12-09-2004 11:42 PM