Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Mixing Server and Client Code

 
 
Lloyd Sheen
Guest
Posts: n/a
 
      11-18-2003
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.


 
Reply With Quote
 
 
 
 
Dales
Guest
Posts: n/a
 
      11-18-2003
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>
 
Reply With Quote
 
 
 
Reply

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 sunithab@gmail.com 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 womanontheinside@yahoo.com C++ 4 12-09-2004 11:42 PM



Advertisments