473,783 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1099
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.EventArg s) 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("Ite m One")
alVals.Add("1")
alText.Add("Ite m Two")
alVals.Add("2")
alText.Add("Ite m Three")
alVals.Add("3")

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

myListBox.Attri butes.Add("onch ange", "test(this) ")
End If
End Sub

HTML snippet:

<HEAD>
<title>WebForm1 </title>
<script language="javas cript">
function test(select) {
var i = select.selected Index
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
5078
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 they press "Cancel" they call another ASPX function. My code now is: System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=""JavaScript"">" & vbCrLf) System.Web.HttpContext.Current.Response.Write("if (confirm('Are you sure you want to...
9
1355
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 reference to system.windows.forms. The app will compile with no problems but for some reason the form won't launch when the method it's in is called. The next step will be to try and put the form in a class lib on the server unless someone knows...
5
1526
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 I access an html field from ASP.net? Or better yet, how do I access server controls from javascript? The latter would be possible if ASP.net always gives the textboxes the excat same ID.
10
2053
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 whole day is then displayed in cels of a table. The user has then to click in a cel representing a hour of the day and an object (book ..), and finally click on the submit button to insert that reservation in the database. My problem is: there...
2
1368
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 monthy payment is displayed. When I design apps like this, I like to clear out result fields like "monthly payment" the minute the user changes any of the parameters of the mortgage. Doing that server-side looks easy enough, but I'd want
28
3102
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 applications, I decide to write it in C instead of C++. However, I thought it might be convenient to use some C++ code at some misc places. I'm aware that, I could always use the C++ compiler to get it work.
7
1540
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 - because it needs to do a round-trip to the server - first. And when it gets back, my other routine will over-write the text as "34 records found" Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
1
1187
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
3199
by: Tom Louchbaum | last post by:
Is there someway to tell who has the *.DB open on a network?
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4044
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.