p2p.wrox.com Forums

Need to download code?

View our list of code downloads.

Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
I forgot my password
Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 27th, 2009, 05:12 AM
Authorized User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Jan 2009
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default TextChanged Event Not Firing

Hi,

Whenever I enter a value in the textbox i want to get the values related to that of text value.without button click i should raise the event...

Code:
 protected void Page_Load(object sender, EventArgs e)
    {
      

            Label1.Text = DateTime.Now.ToLongDateString() + ":No Change";
        
    }
 protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        
        Label1.Text = DateTime.Now.ToLongDateString() + ":CHANGED";
    }
HTML Code:
<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"  AutoPostBack="true"></asp:TextBox>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
whenever i enter a value in the textbox and press Enter button then the code is coming....i should not get like that without entering the enter button i should get the values.On text Focus only i should get the values....
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old August 27th, 2009, 06:01 AM
Imar's Avatar
Wrox Author
Points: 36,330, Level: 83
Points: 36,330, Level: 83 Points: 36,330, Level: 83 Points: 36,330, Level: 83
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,699
Thanks: 13
Thanked 303 Times in 299 Posts
Default

You're setting the text box value after each post back as well and thus TextChanged doesn't fire. Wrap your code in Page_Load in a !PostBack block:

Quote:
if (!Page.IsPostBack)
{
Label1.Text = DateTime.Now.ToLongDateString() + ":No Change";
}
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB and ASP.NET 2.0 Instant Results.

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old September 16th, 2009, 07:20 AM
Authorized User
Points: 186, Level: 3
Points: 186, Level: 3 Points: 186, Level: 3 Points: 186, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 50
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Text changed event will be fire on going out of the text box(onBlur in client)
__________________
Pon Saravanan
VB Knowledgebase, Car PC,
VB .Net Tutorial
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old September 16th, 2009, 07:27 AM
Imar's Avatar
Wrox Author
Points: 36,330, Level: 83
Points: 36,330, Level: 83 Points: 36,330, Level: 83 Points: 36,330, Level: 83
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,699
Thanks: 13
Thanked 303 Times in 299 Posts
Default

Quote:
Text changed event will be fire on going out of the text box(onBlur in client)
This is absolutely not true. TextChanged fires at the server after a PostBack when the text has been changed somehow compared to the initial load of the page. It is not, in any way, related to JavaScript's onblur or any other client event. You can have TextChanged fire on browsers that have JavaScript disabled or that don't support JvaaScript.

Simply put: TextChanged fires when the text for a control has changed at the client, irrespective of the actual method used to change that text (a user, client side JavaScript etc).

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB and ASP.NET 2.0 Instant Results.

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old September 16th, 2009, 10:29 PM
Authorized User
Points: 186, Level: 3
Points: 186, Level: 3 Points: 186, Level: 3 Points: 186, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 50
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by Imar View Post
This is absolutely not true. TextChanged fires at the server after a PostBack when the text has been changed somehow compared to the initial load of the page. It is not, in any way, related to JavaScript's onblur or any other client event. You can have TextChanged fire on browsers that have JavaScript disabled or that don't support JvaaScript.

Simply put: TextChanged fires when the text for a control has changed at the client, irrespective of the actual method used to change that text (a user, client side JavaScript etc).

Cheers,

Imar
the textchanged event fires only after you are leaving away the text box by taping a tab or, clicking on another control in case of AutoPostBack=true for the respective control.

it is hard for asp.net engine to do postback for every letter change in the textbox. may be the naming of the event is confusing here. Thats the reason i have put onBlur in the brackets for the understanding purpose. I have verified this with vb.net and c#.net and it fires only on leaving the textbox(same as onBlur)

NOTE: the textbox control by design will NOT fire event(TextChanged) for every keypress.
__________________
Pon Saravanan
VB Knowledgebase, Car PC,
VB .Net Tutorial

Last edited by pons_saravanan : September 16th, 2009 at 11:36 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old September 17th, 2009, 04:14 AM
Imar's Avatar
Wrox Author
Points: 36,330, Level: 83
Points: 36,330, Level: 83 Points: 36,330, Level: 83 Points: 36,330, Level: 83
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,699
Thanks: 13
Thanked 303 Times in 299 Posts
Default

Quote:
the textchanged event fires only after you are leaving away the text box by taping a tab or, clicking on another control in case of AutoPostBack=true for the respective control.
No, no, no. You're mixing things up.

What you are describing here is AutoPostBack which causes the TextBox to submit the form to the server once you leave the TextBox control. This is indeed where onblur comes it. As soon as you trigger a JavaScript onblur for a TextBox with AutoPostBack to true it does a postback to the server. And you're right: it only does that for the entire text, not for each letter.

But all of this has nothing to do with TextChanged. Like I said, TextChanged fires at the server, after a post back, when the text in the control has changed. Not for every letter indeed, but once for every postback. It does that after a postback which can be triggered by a plain button (no JavaScript involved) or because you set AutoPostBack to true on the textbox. However, the use of JaavScript to handle onblur and submit to the server is ooure coincidence; it's not related to TextChanged; it's just a means to submit back to the server.

You can easily witness the behavior by creating a form with a Button, a TextBox (without AutoPostBack) and a handler for TextChanged. You'll see that no JavaScipt is needed or used. You enter some text, hit the button (which causes the TextBox to loose its focus, causing an onblur but NOT causing a PostBack) and then the form is submitted to the server where TextChanged is fired.

So, this is all a server side solution. Onblur has nothing to do with it, although you can use it to force a postback to the server.

Hope this clariefies things and clears up your confusion.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB and ASP.NET 2.0 Instant Results.

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #7 (permalink)  
Old September 17th, 2009, 04:30 AM
Authorized User
Points: 186, Level: 3
Points: 186, Level: 3 Points: 186, Level: 3 Points: 186, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 50
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by Imar View Post
No, no, no. You're mixing things up.

What you are describing here is AutoPostBack which causes the TextBox to submit the form to the server once you leave the TextBox control. This is indeed where onblur comes it. As soon as you trigger a JavaScript onblur for a TextBox with AutoPostBack to true it does a postback to the server. And you're right: it only does that for the entire text, not for each letter.

But all of this has nothing to do with TextChanged. Like I said, TextChanged fires at the server, after a post back, when the text in the control has changed. Not for every letter indeed, but once for every postback. It does that after a postback which can be triggered by a plain button (no JavaScript involved) or because you set AutoPostBack to true on the textbox. However, the use of JaavScript to handle onblur and submit to the server is ooure coincidence; it's not related to TextChanged; it's just a means to submit back to the server.

You can easily witness the behavior by creating a form with a Button, a TextBox (without AutoPostBack) and a handler for TextChanged. You'll see that no JavaScipt is needed or used. You enter some text, hit the button (which causes the TextBox to loose its focus, causing an onblur but NOT causing a PostBack) and then the form is submitted to the server where TextChanged is fired.

So, this is all a server side solution. Onblur has nothing to do with it, although you can use it to force a postback to the server.

Hope this clariefies things and clears up your confusion.

Cheers,

Imar
i never said anywhere that javascript is doing postback, i said for understanding purposes i refered onBlur nothing more than that. Can you please re read the original requirement asked by the thread starter and re read your post again. You will know what i meant.
__________________
Pon Saravanan
VB Knowledgebase, Car PC,
VB .Net Tutorial
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old September 17th, 2009, 04:41 AM
Imar's Avatar
Wrox Author
Points: 36,330, Level: 83
Points: 36,330, Level: 83 Points: 36,330, Level: 83 Points: 36,330, Level: 83
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,699
Thanks: 13
Thanked 303 Times in 299 Posts
Default

You said this initially:
Quote:
Text changed event will be fire on going out of the text box(onBlur in client)
This is simply not true. TextChanged does NOT fire when going out of the text box. It fires, at the server, when the text has changed compared to the initial load of the page. You can have a TextChanged fired without ever entering (and thus without ever going out of) the text box. So, rather than explaining things, I think your original statement just confuses matters....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Everyone is unique, except for me.
Author of Beginning ASP.NET 4 : in C# and VB, Beginning ASP.NET 3.5 : in C# and VB and ASP.NET 2.0 Instant Results.

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old September 17th, 2009, 04:58 AM
Authorized User
Points: 186, Level: 3
Points: 186, Level: 3 Points: 186, Level: 3 Points: 186, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2008
Location: singapore, singapore, Singapore.
Posts: 50
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
Originally Posted by Imar View Post
You said this initially:This is simply not true. TextChanged does NOT fire when going out of the text box. It fires, at the server, when the text has changed compared to the initial load of the page. You can have a TextChanged fired without ever entering (and thus without ever going out of) the text box. So, rather than explaining things, I think your original statement just confuses matters....

Cheers,

Imar
can you please check your answer respect to the question asked by the thread starter?

Is it anywhere relevant to the question? He is not asking how the event is working. he is asking why the event is not firing without pressing enter .

if you still not able understand his queries i am giving up here. and the readers of this forums will understand what i am talking about.
__________________
Pon Saravanan
VB Knowledgebase, Car PC,
VB .Net Tutorial
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
selectedindexchanged event not firing kaliaparijat ASP.NET 2.0 Professional 1 June 5th, 2008 09:58 AM
textchanged event Komila ASP.NET 2.0 Basics 5 August 5th, 2007 02:09 PM
Event Firing tobriain C# 1 June 12th, 2007 09:19 AM
Custom event not firing flegel ASP.NET 2.0 Professional 0 February 23rd, 2007 06:31 AM
problem with textchanged event alyeng2000 ASP.NET 1.0 and 1.1 Basics 0 February 15th, 2004 05:24 AM



All times are GMT -4. The time now is 11:26 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
© 2010 Wiley Publishing, Inc