[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Cannot get TextChanged event to fire

Posted on 2006-04-08
7
Medium Priority
?
391 Views
Last Modified: 2008-01-09
Using Visual Studio, vb.net:  I need to have a text box fill in dynamically without page postback either of two other text boxes change in value.  I have tried using the change event in code-behind for the text boxes and I've tried using javascript in the HTML, all to no avail.  Any suggestions or points to help would be welcome!!
0
Comment
Question by:aibar
  • 3
  • 3
7 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 16409136
If you're trying to use the TextChanged event then that will cause a postback, but only if you have AutoPostBack set to true on the control. Otherwise the event is cached until the next time a Postback is triggered.

You should be able to use javascript on the client. Can you give us an idea of exactly what needs to happen and when ?
0
 

Author Comment

by:aibar
ID: 16409634
I have three text boxes.  When text box #1 or #2  changes in value, I need text box #3 to change in value.  So simple, and I knew how to do it before in regular ASP, but for the life of me cannot do it now?!  Thank you for any help!
0
 
LVL 6

Accepted Solution

by:
enwhysee earned 2000 total points
ID: 16409813
How about something like this? Here, when either textboxes 1 and 2 change in value, textbox 3 will become the concatenation of their values. This doesn't use a postback at all.


<script language="javascript">
function onTBChange()
{
   var textbox3ID="<% Response.Write(TextBox3.ClientID); %>";
   document.getElementById(textbox3ID).value =
       document.getElementById('TextBox1').value + document.getElementById('TextBox2').value;
}
</script>    
   
    <input type="text" ID="TextBox1" onchange="onTBChange()" onblur="onTBChange()"  onkeydown="onTBChange()" />
    <input type="text" ID="TextBox2" onchange="onTBChange()" onblur="onTBChange()"  onkeydown="onTBChange()"/>
    <asp:TextBox ID="TextBox3" runat="server" />
   

Note that only TextBox3 is an ASP.NET textbox, and only its value will get submitted with the form post for cleanliness (since I am assuming you don't need the values of textboxes 1 & 2 later.)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:aibar
ID: 16411402
Perfect!  Works perfectly and I've learned a lot from this little snippet you gave. Thanks!
0
 
LVL 6

Expert Comment

by:enwhysee
ID: 16411432
Glad it was of help! :)

I just re-read my post, and my comment in the last sentence was of course wrong. The values of TextBox1 & TextBox2 will also be submitted along with the rest of the form data when you do a postback, since they're both input elements (even if they aren't marked as runat="server"). But for practical intents and purposes it doesn't matter a whole lot.

0
 

Author Comment

by:aibar
ID: 16411523
One more note - I got an error when I first ran it that I had an illegal character.  Removing the first ";" from this line:
 var textbox3ID="<% Response.Write(TextBox3.ClientID); %>";
solved the problem.  Thanks again!
0
 
LVL 6

Expert Comment

by:enwhysee
ID: 16411564
I see, it must be because you're using VBScript instead of C#. In C# the ; would be required, but in VB it is invalid.
Take care!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month19 days, 2 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question