Any way to change the background color of a asp:Textbox
with the event OnClientClick
of a asp:Button
from JavaScript
without using:
document.getElementById("un_textbox").style.background = '#f88067';
The button is defined as follows:
<asp:Button ID="re" runat="server" autopostback="True" OnClick="re_Click" OnClientClick="return comprueba();" style="height: 32px" Text="Registrate" />
The only way I could achieve it is by declaring a js variable, assigning it the id of the
div
and then passing the variable as a parameter to the function:And in your js file:
I recommend that you stop reneging on pure javascript and install a library like JQuery as an alternative and not so cumbersome way.
Usually ASPX elements when rendered in HTML end up with the ID changed
so a call for example to instantiate that button via id, placing it as it was named would not work:
but instead you can use a pseudo regular expression to match it to make it work.
That said, given a textbox let's say the following, if it is an html component either of the two forms will work if it is an asp component use the second to reference, and to change the background color it would be:
finally an example using jquery:
you must access the id of your div