Solved

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

Posted on 2008-06-25
6
875 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
 
LVL 11

Expert Comment

by:Vivek Thangaswamy
ID: 21871756
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

739 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