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

Why event not firing right away

tfs
I have a small page I am using to play around with events and am
confused why the "onTextChanged" event doesn't fire until I press the
button?

I am trying to allow the user to put something in Textbox 1 and then
when they exit it, have the event fire to make the Textbox 2 =
TextBox 1.

Why doesn't it happen right away? And what would be the best way to
make it do this?

Here is the page:
<%@ Page Language="VB" Trace="True"
Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<html>
<head>
<title>Contour Intranet</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<script runat="server">
Sub Page_Init (Sender as Object, E as EventArgs)
trace.warn("In Page_init - lblAverage = " &
lblAverage.text & "<br>")
End Sub

Sub Page_PreRender (Sender as Object, E as EventArgs)
trace.warn("In Page_PreRender<br>")
End Sub

Sub Page_Load (Sender as Object, E as EventArgs)
trace.warn("in Page_load<br>")
if IsPostBack
trace.warn("in Page_load -
IsPostBack<br>")
else
trace.warn("in Page_load - Not
IsPostBack<br>")
end if
trace.warn("Exit Page_load<br>")
end sub

Sub Page_Unload (Sender as Object, E as EventArgs)
trace.warn("In Page Unload<br>")
End Sub

Sub changeText2 (s as Object, E as EventArgs)
trace.warn("In changeText2<br>")
lblAverage2.Text = lblAverage.Text
End Sub

Sub OnButton_Click (Sender as Object, E as EventArgs)
trace.warn("In OnButton_Click<br>")
end sub

</script>

<form runat="server">
Average Time to Process:
<asp:textbox
ID="lblAverage"
onTextChanged="changeText2"
text="Textbox 1"
Runat="Server" />

<asp:textbox
ID="lblAverage2"
text="Textbox 2"
Runat="Server" />

<br><br>
Would you like to continue processing?<br><br>
<asp:button ID="btnContinue"
onClick="OnButton_Click" runat="server"
Text="Process" />

</form>
</body>
</html>
Thanks,

Tom

Nov 18 '05 #1
3 2251
What may be the problem is that you do not have AutoPostBack property set to true on the TextBox. If you have the code that transfers the contents of textbox1 to textbox2 on the server-side (codebehind), the textchanged event will only occur there, so the page needs to return to the server to accomplish that. It works when you click the button because the button causes a postback. AutoPostBack will automatically cause the page to reload when the text in the textbox has changed.

Before you go ahead and turn AutoPostBack to true for the textbox, consider adding javascript code to the TextChanged event of the textbox so that the transfer occurs on the client. This way the page does not have to reload and is much better for performance and it will have a more seemless feel.

hope this helps,
John
"tfs" wrote:
I have a small page I am using to play around with events and am
confused why the "onTextChanged" event doesn't fire until I press the
button?

I am trying to allow the user to put something in Textbox 1 and then
when they exit it, have the event fire to make the Textbox 2 =
TextBox 1.

Why doesn't it happen right away? And what would be the best way to
make it do this?

Here is the page:
<%@ Page Language="VB" Trace="True"
Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<html>
<head>
<title>Contour Intranet</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<script runat="server">
Sub Page_Init (Sender as Object, E as EventArgs)
trace.warn("In Page_init - lblAverage = " &
lblAverage.text & "<br>")
End Sub

Sub Page_PreRender (Sender as Object, E as EventArgs)
trace.warn("In Page_PreRender<br>")
End Sub

Sub Page_Load (Sender as Object, E as EventArgs)
trace.warn("in Page_load<br>")
if IsPostBack
trace.warn("in Page_load -
IsPostBack<br>")
else
trace.warn("in Page_load - Not
IsPostBack<br>")
end if
trace.warn("Exit Page_load<br>")
end sub

Sub Page_Unload (Sender as Object, E as EventArgs)
trace.warn("In Page Unload<br>")
End Sub

Sub changeText2 (s as Object, E as EventArgs)
trace.warn("In changeText2<br>")
lblAverage2.Text = lblAverage.Text
End Sub

Sub OnButton_Click (Sender as Object, E as EventArgs)
trace.warn("In OnButton_Click<br>")
end sub

</script>

<form runat="server">
Average Time to Process:
<asp:textbox
ID="lblAverage"
onTextChanged="changeText2"
text="Textbox 1"
Runat="Server" />

<asp:textbox
ID="lblAverage2"
text="Textbox 2"
Runat="Server" />

<br><br>
Would you like to continue processing?<br><br>
<asp:button ID="btnContinue"
onClick="OnButton_Click" runat="server"
Text="Process" />

</form>
</body>
</html>
Thanks,

Tom

Nov 18 '05 #2
Hi Tom,

Try settting AutoPostback="True" in the textboxes and see what that does?

<asp:textbox
ID="lblAverage2"
text="Textbox 2"
Runat="Server"
AutoPostback="true"/>

The server doesn't know anything until the data has been sent to it. The
button click accomplishes the serverside event as you would expect.

A way of making the event happen earlier is Autopostback. It fires a
client-side event when you tab away from the changed textbox. The
client-side event forces a server-side event that can be processed.

You might want to do View > Source on the page when AutoPostback="True".
You'll see some interesting JavaScript emited by ASP.NET.

Ken
Microsoft MVP [ASP.NET]

"tfs" <tf*@dslextreme-dot-com.no-spam.invalid> wrote in message
news:40**********@Usenet.com...
I have a small page I am using to play around with events and am
confused why the "onTextChanged" event doesn't fire until I press the
button?

I am trying to allow the user to put something in Textbox 1 and then
when they exit it, have the event fire to make the Textbox 2 =
TextBox 1.

Why doesn't it happen right away? And what would be the best way to
make it do this?

Here is the page:
<%@ Page Language="VB" Trace="True"
Debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<html>
<head>
<title>Contour Intranet</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<script runat="server">
Sub Page_Init (Sender as Object, E as EventArgs)
trace.warn("In Page_init - lblAverage = " &
lblAverage.text & "<br>")
End Sub

Sub Page_PreRender (Sender as Object, E as EventArgs)
trace.warn("In Page_PreRender<br>")
End Sub

Sub Page_Load (Sender as Object, E as EventArgs)
trace.warn("in Page_load<br>")
if IsPostBack
trace.warn("in Page_load -
IsPostBack<br>")
else
trace.warn("in Page_load - Not
IsPostBack<br>")
end if
trace.warn("Exit Page_load<br>")
end sub

Sub Page_Unload (Sender as Object, E as EventArgs)
trace.warn("In Page Unload<br>")
End Sub

Sub changeText2 (s as Object, E as EventArgs)
trace.warn("In changeText2<br>")
lblAverage2.Text = lblAverage.Text
End Sub

Sub OnButton_Click (Sender as Object, E as EventArgs)
trace.warn("In OnButton_Click<br>")
end sub

</script>

<form runat="server">
Average Time to Process:
<asp:textbox
ID="lblAverage"
onTextChanged="changeText2"
text="Textbox 1"
Runat="Server" />

<asp:textbox
ID="lblAverage2"
text="Textbox 2"
Runat="Server" />

<br><br>
Would you like to continue processing?<br><br>
<asp:button ID="btnContinue"
onClick="OnButton_Click" runat="server"
Text="Process" />

</form>
</body>
</html>
Thanks,

Tom


Nov 18 '05 #3
tfs
That worked.

Now when would I do the AutoPostBack and when the Javascript code?

Why is one better than the other?

I assume that if this is the Internet, I would want to use the
Javascript as going back to the server might take a while and go
through many routers and servers.

But what about an intranet? Would it make a difference there?

Also, couldn't I also use VBScript for my clientside code?

Thanks,

Tom

Nov 18 '05 #4

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

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
4
by: Larry Morris | last post by:
The following code, pasted into a web form with a link button on it, will cause the page_unload event to fire twice. If I remove the response.redirect, the problem goes away :). I've got a work...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
5
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.