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

Surprise with Textbox1.Text

To my great surprise the following code is not working. I expect
TextBox1.Text to be
changed each time the dropdownlist selected index changes. It works in
Windows application but
surprisingly not not WebApplication web form.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
DropDownList1.Items.Add("Australia")
DropDownList1.Items.Add("Belgium")
DropDownList1.Items.Add("Canada")
DropDownList1.Items.Add("India")
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = DropDownList1.SelectedItem.Text
End Sub

Pls advise what's wrong with the code.

Thank you,
Rakesh
Apr 25 '06 #1
3 1426
You can't expect a web application to work the same as a windows application.

You have to set the AutoPostBack option of the dropdown list, so that it
will reload the page from the server when the selected index changes.
Apr 25 '06 #2
Postbacks are expensive, especially if the server doesn't care that the
dropdown selected value has changed. Simple client side javascript can
provide you the same thing without postback.

set the onSelectedChange property of the dropdown = "fnIchanged();"

create a script (directly in the HTML, or write it out prior to rendering.)

<script language="javascript" ...>
function fnIchanged()
{
TextBox1.value =
DropDownlist1.options[DropDownlist1.SelectedIndex].value;
}
</script>

Posting back to the server on every value change, while easier to code for,
is still extra round trips over the wire. When your client can do the work
for you, let the client do the work, preserve your bandwidth, memory and CPU
for the hard stuff.
"Guffa" <Gu***@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
You can't expect a web application to work the same as a windows
application.

You have to set the AutoPostBack option of the dropdown list, so that it
will reload the page from the server when the selected index changes.

Apr 25 '06 #3
So correct. Valuable input. :)

That's the reason AutoPostback is not on by default.

Some corrections and modernisations of the Javascript, though:

<script type="text/javascript" ...>
function fnIchanged()
{
document.getElementById('TextBox1').value =
document.getElementById('DropDownlist1').options[document.getElementById('DropDownlist1').selectedI ndex].value;
}
</script>

Apr 25 '06 #4

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

Similar topics

3
by: polarz | last post by:
I'm having trouble getting items from different classes to display in my textBox. e.g. private void button2_Click(object sender, System.EventArgs e) { someData sd = new someData();...
5
by: Hareth | last post by:
Is there a way to take a text, from a textbox & later passwordChar the text. I'm not using a masked textbox. I tried: textBox1.PasswordChar = '*'; but this didn't change my text. I know how...
4
by: I_AM_DON_AND_YOU? | last post by:
A simple query: I have a textbox with multiline=true. Also there is a button1. In button1's click the code written is textbox1.lines(0) = "Microsoft" textbox2.lines(1) = "Visual Basic" ...
4
by: Ken Soenen | last post by:
The code below illustrates my problem which is: I'm trying to access the TEXT from TextBox1 which is on Form1. Line "aa = Form1.TextBox1.Text" produces the error--Reference to a non-shared member...
3
by: cj | last post by:
When I select textbox1 I want all text in it to be selected. I used the textbox1_enter event to run textbox1.selectall() This works if I tab to the box but not if it is selected by clicking on...
1
by: emailseshu | last post by:
Hi, Iam trying to check the Client Side CallBack Feature in ASP.NET Iam able to call th RaiseCallbackEvent from the Client Side Javascript Function but when I go to the debug mode to check the...
3
by: Mark Ivey | last post by:
VS.Net 2002 - Visual Basic I am pretty new to VB in general, and I am having a bit of difficulty finding the right method or property to link a textbox to a filelistbox. Here is the...
0
by: ricklafleur | last post by:
I'm using CSharp/ASP.NET 2.0 and trying to create a simple search page that records the user query in the URL (so can be bookmark) and also re-writes the query int the original TextBox. This only...
2
by: zhang | last post by:
I want to click a button and TextBox1 show the content of the file "1.txt" but failed why?? Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.