Solved

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

Posted on 2008-06-25
6
869 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
  • 4
6 Comments
 
LVL 11

Expert Comment

by:anuragal
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 11

Expert Comment

by:anuragal
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:anuragal
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:
anuragal 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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…

773 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