Textbox Color Change [Resolved]

Posted by jnrprogrammer-22113 under ASP.NET on 9/26/2013 | Points: 10 | Views : 3332 | Status : [Member] | Replies : 5
Hi All,

I am creating a web form with many Text boxes, So i want the Text box to change color to red when the character its wrong. I also want the color to change to blue when i point the textbox


Can this happen using Regular Expression,if yes....Please help me. I tried java script but it didn't work out.

I have attached 2 forms that i would like to apply the styling on.

Thanks

Sitholimela


Responses

Posted by: Bandi on: 9/26/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved

private void TextChangedEventHandler(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if(tb != null){
if(tb.Text.Length > 0){
//set color
}
else{
//set color
}
}
}

...

//Loop through your controls (textboxes) and set handler

foreach(Control c in this.Controls){

if(c is TextBox){
c.TextChanged += TextChangedEventHandler;
}

}


Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

jnrprogrammer-22113, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/26/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Refer this link for textbox background color change
http://www.aspsnippets.com/Articles/Change-TextBox-Background-color-on-Focus.aspx
Javascript change color of text and background to input value
http://stackoverflow.com/questions/16625618/javascript-change-color-of-text-and-background-to-input-value?rq=1

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

jnrprogrammer-22113, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/26/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function TestClr() {
document.getElementById("Txt1").style.backgroundColor = 'red';
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">

<asp:TextBox ID="Txt1" runat ="server" ></asp:TextBox>

<asp:Button ID="bt1" runat ="server" OnClientClick ="return TestClr();" Text ="Color" />

</form>
</body>
</html>


Mark as Answer if its helpful to you

jnrprogrammer-22113, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/26/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function TestClr() {
document.getElementById("Txt1").style.backgroundColor = 'red';
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">

<asp:TextBox ID="Txt1" runat ="server" ></asp:TextBox>

<asp:Button ID="bt1" runat ="server" OnClientClick ="return TestClr();" Text ="Color" />

</form>
</body>
</html>


Mark as Answer if its helpful to you

jnrprogrammer-22113, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/26/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this too
http://www.dreamincode.net/forums/topic/206754-changing-textbox-text-color-onclick/
http://www.aspdotnet-suresh.com/2012/10/jquery-change-textbox-background-color.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

jnrprogrammer-22113, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response