JS to change the value on a server side control?

dennisvb

Member
Joined
Nov 19, 2009
Messages
10
Programming Experience
10+
I am trying to use JS to change the value on a server side control. Itry two ways in this function neither works.

VB.NET:
Expand Collapse Copy
         <script language="javascript"  type="text/javascript"  >

             function Change_text() 
              {
                   ('<%= Button1.ClientID %>').text = "DO IT";
                   document.getElementById('<%=Button1.ClientID %>').text = "DO IT!!!";
                  
             } 

</script>

I know the script is running because I've walked through it.

How can I change a contorls attributes?

Any help would be appreciated.

Denis
 
Try this out:

VB.NET:
Expand Collapse Copy
document.getElementById("<%=Button1.ClientID%>").value=="DO IT!!!";

Even this will not work. But if you remove the second equal it will :)

VB.NET:
Expand Collapse Copy
document.getElementById("<%=Button1.ClientID%>").value[B]=[/B]"DO IT!!!";
 
That works.

Why doesn't it work when I try something like:

VB.NET:
Expand Collapse Copy
 document.getElementById("<%=Button1.ClientID%>").BackColor="Blue"

I know the script is executing because I have an alert box that goes off.

How can I change other attributes like Color and Size?
 
Last edited:
Javascripts operates at client-side, where all server controls are represented as Html markup code, to manipulate them you have to treat them as such. For example the Button server control is displayed as Input tag in web page. Using a Html or DHtml reference you can find out how to handle Html elements from Javascript.
 
That works.

Why doesn't it work when I try something like:

VB.NET:
Expand Collapse Copy
 document.getElementById("<%=Button1.ClientID%>").BackColor="Blue"

I know the script is executing because I have an alert box that goes off.

How can I change other attributes like Color and Size?

You should refer the style prior ... e.g.
VB.NET:
Expand Collapse Copy
document.getElementById("<%=Button1.ClientID%>").style.backgroundColor = "Blue"
 
Back
Top