Avatar of Mr_Shaw
Mr_Shaw

asked on 

Server tags cannot contain <% ... %> constructs.

I have created a button which I would like to included a little script to change the button color.

<asp:Button ID="Aim" runat="server" BorderStyle="None" Text="Aim"
    onclick="Aim_Click" Width="56px" OnMouseEnter="this.style.backgroundColor='white';" OnMouseLeave="this.style.backgroundColor=' <%string colorName; colorName = Aim.BackColor.Name.ToString(); Response.Write("#" + colorName.Remove(0, 2));%>';" />

What I get is an error.

Server tags cannot contain <% ... %> constructs.

if I run

<asp:Button ID="Aim" runat="server" BorderStyle="None" Text="Aim"
    onclick="Aim_Click" Width="56px" OnMouseEnter="this.style.backgroundColor='white';" OnMouseLeave="this.style.backgroundColor=' <%Response.Write(Aim.BackColor.Name.ToString());%>';" />

I don't get an error.

Is there a way in which I can pass variables from my seperate C# page to the asp.net/html page. Or is there another method inwhich I can achieve the above.
.NET ProgrammingASP.NETC#

Avatar of undefined
Last Comment
Mr_Shaw

8/22/2022 - Mon