?
Solved

change the background color of textbox inside a datagrid in asp.net 1.1

Posted on 2008-06-25
6
Medium Priority
?
877 Views
Last Modified: 2008-06-26
Hi,

  I have a datagrid, which has a textbox inside the itemtemplate column.
  what i want is, once the user types in a value lesser than 25, i shud change the
background of the the textbox to red immediatly.
If the entered value is changed to a value more than 25, then remove the background color automatically.

how to do this???

Very Urgent ....Thanks
0
Comment
Question by:srk1982
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21871747
Add following code in the ItemDataBound of the Datagrid...

TextBox tx = (TextBox)(e.Item.FindControl("TextBox1"));
tx.Attributes.Add("onKeyPress", "ChangeColor(" + tx.ClientId +  ");");

And in .aspx page add this javascript function

function ChangeColor(obj)
{
      var txtbox = document.getElementById(obj);
            if(txtbox.value < 25)
            {
                  txtbox.backGroundColor = "red";
            }
                                else
                                {
                                              txtbox.backGroundColor = "set default color";
                                }
}


If it doesn't work then please follow the below link to get an idea of various ways to access the textbox

http://forums.asp.net/p/1194696/2077518.aspx

Anurag

0
 

Author Comment

by:srk1982
ID: 21871818
hi anurag,

  some problem in

var txtbox = document.getElementById(obj);

i could not get the txtbox here.

I used like this...

<asp:TextBox OnKeyPress="ChangeColor(this.value);" id=Txt_EML Runat="server">
________________________________________________________
function ChangeColor(obj)
{
    var txtbox = document.getElementById(obj);

    if(obj < 25)
    {
            txtbox.backGroundColor = "red";
    }
      else
      {
                  txtbox.backGroundColor = "White";
    }
}

____________________________________________________________

Here when i put the alert statement, like
alert(obj) i am getting the value.
but when i put
alert(txt.value), i am getting error - object required.

i think some problem in
    var txtbox = document.getElementById(obj);
it is not getting the getelementbyid.

Urgent...thanks
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21872175
as i said put the code in itemdatabound for attaching the javascript function to the textbox.

Anurag
0
 
LVL 11

Expert Comment

by:Anurag Agarwal
ID: 21872181
I have not seen completely what you wrote in yur mail...

try
<asp:TextBox OnKeyPress="ChangeColor(this);" id=Txt_EML Runat="server">

Anurag
0
 
LVL 11

Accepted Solution

by:
Anurag Agarwal earned 1500 total points
ID: 21872248
For setting the color you have to do like this

var eC='#E5E5E5'; //error color
var dC='#FFFFFF'; //default color

then set accordingly, keep in mind that javascript is case sensitive..

use TextBox1.style.backgroundColor=eC or TextBox1.style.backgroundColor=dC on conditions

Anurag


0

Featured Post

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.

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…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 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