473,509 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox Color Changes using Javascript

12 New Member
Hello,
I know this question has been asked everywhere but I cannot find a solution that will help me. I hope someone here has some ideas.

I have 9 TextBoxes in a Repeater Control. A user can edit dates in these textboxes. If the user changes the date, I want to dynamically change the color of the background of the textbox. When the data is saved I will set the textboxes back to it's original background(I can do this in the code-behind)
Right now I can get it to change but I have to do a postback in order to do it on the TextChanged Event of the TextBox. This page has 14 rows with 9 textboxes in each so postbacks are tedious to the user after 3 of them.
Can anyone help me accomplish this in Javascript?

Thanks in advance!
Oct 2 '07 #1
6 10511
acoder
16,027 Recognized Expert Moderator MVP
Use the text box's onchange event to change the color.
Oct 2 '07 #2
stormcandi
12 New Member
Use the text box's onchange event to change the color.
I have tried using the onTextChanged Event but no avail unless the page posts back which I do not want it to do.

This is in my code-behind:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  foreach (RepeaterItem item in rptrShots.Items)
  3.  {
  4.       TextBox txt1 = (TextBox)item.FindControl("txt1");
  5.        txt1.Attributes["onTextChanged"] = "ChgColor('" + txt1.UniqueID + "');";
  6.  }
  7.  
This is in the mark-up:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript"> 
  2. function ChgColor(sender)
  3. {
  4.     sender.style.backgroundColor = '#CC3300';
  5. }
  6. </script>
  7.  
Oct 2 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Can you not use normal JavaScript like, e.g.
[HTML]<input type="text" onchange="chgColor(this);">[/HTML]
Oct 2 '07 #4
stormcandi
12 New Member
Can you not use normal JavaScript like, e.g.
[HTML]<input type="text" onchange="chgColor(this);">[/HTML]
No I get an error when I try to do it that way.
I get these types of errors:
Invalid expression term ')

This is what the markup for the textbox looks like:
[HTML]<asp:TextBox ID="txt1" runat="server" Text = '<%# Bind("Dose1") %>' MaxLength = "10" Width = "90%" OnTextChanged= "chgColor();"/>[/HTML]
Oct 3 '07 #5
stormcandi
12 New Member
No I get an error when I try to do it that way.
I get these types of errors:
Invalid expression term ')

This is what the markup for the textbox looks like:
[HTML]<asp:TextBox ID="txt1" runat="server" Text = '<%# Bind("Dose1") %>' MaxLength = "10" Width = "90%" OnTextChanged= "chgColor();"/>[/HTML]
Does anyone have any ideas on how to get this to work?
Oct 12 '07 #6
acoder
16,027 Recognized Expert Moderator MVP
How does that turn out on the client-side?
Oct 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2466
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
2
5655
by: Manish | last post by:
Hey folks I am having a weird problem in ASP .Net. My page is in C#. I have a datagrid, which populates based on selection in drop down box on ASP page. This datagrid has template textbox colum in...
2
3886
by: Pham Nguyen | last post by:
Has anyone seen an example of a textbox server control that has built-in client-side validation? I'd like to build a server control that extends the System.Web.UI.WebControls.TextBox class to allow...
9
10088
by: Jerry | last post by:
In limiting textbox input to 500 characters I would like to include a dynamic count of characters input while the user is typing into a textbox. This would obviously be a client side control,...
3
1692
by: Henry | last post by:
Hi. I've also posted this at another discussion board and here is the original question. ------------------------- "I have this problem and I don't know what I can do. First of all, I have a...
6
13881
by: JohnR | last post by:
I have a table with 1 row which is used to hold some application wide items (one item per field, hence I only need 1 row). I want to bind one of the fields to a textbox. After setting up the...
1
3194
by: rn5a | last post by:
I want to create a custom control that encapsulates a Button & a TextBox. When the Button is clicked, the user is asked a question using JavaScript confirm (which shows 2 buttons - 'OK' &...
6
2886
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
9
2996
by: David C | last post by:
I have an asp.net page that contains a FormView with several controls bound to a SqlDataSource. One of the controls is a TextBox bound to a date column. I have the following additional properties...
0
7233
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
7342
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,...
0
7410
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
5650
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,...
0
4729
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...
0
3215
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...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
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...

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.