Yahoo Search

Search the web Search this site

Live Search

Google Search

Custom Search

Translate this Web Site to

Friday, July 23, 2010

Changing the Control Style at Runtime using the ASPX

Recently I changed the style of some controls in my ASPX page at runtime based on the values set on another control in my page. For example the color of the table is changed based on the radio button that was selected and the color of the button is changed according to the text that was typed in the textbox. Hope this is helpful.

  1. <html xmlns="">
  2. <head runat="server">
  3.     <title>Changing the Control Style</title>
  4.      <style type="text/css">
  5.         .Style1
  6.         {
  7.             background-color: Red;
  8.         }
  9.         .Style2
  10.         {
  11.             background-color: Blue;
  12.         }
  13.     </style>
  14. </head>
  15. <body>
  16.     <form id="form1" runat="server">
  17.         <asp:RadioButton ID="RadioButton1" runat="server" Text="Red" GroupName="1" Checked="True" AutoPostBack="True" />
  18.         <asp:RadioButton ID="RadioButton2" runat="server" Text="Blue" GroupName="1" AutoPostBack="True" />
  19.         <!-- Styling the table based on the radio button selection. -->
  20.         <table class="<% if(RadioButton1.Checked) { %> Style1 <% } else { %> Style2 <% } %>">
  21.             <tr>
  22.                 <td> &nbsp; See the change... </td>
  23.             </tr>
  24.             <tr>
  25.                 <td> &nbsp; </td>
  26.             </tr>
  27.         </table>
  28.         <asp:TextBox ID="TextBox1" runat="server" MaxLength="3"></asp:TextBox>
  29.         <!-- Styling the button based on the textbox value. -->
  30.         <input id="Button1" type="submit" value="button"
  31.                class="<% if(TextBox1.Text=="") { %> Style1 <% } else { %> Style2 <% } %>" />
  32.     </form>
  33. </body>
  34. </html>

Output looks as below.


Anonymous said...

TOP 30 GOOGLE RUS shops!!!
Special for you -30%

for url code)))

Anonymous said...

hello admin found your site via search engine but it was hard to find and I see you could have more visitors because there are not so many comments yet. I have found site which offer to dramatically increase traffic to your blog they claim they managed to get close to 1000 visitors/day using their services you could also get lot more targeted traffic from search engines as you have now. I used their services and got significantly more visitors to my website. Hope this helps :) They offer improve pagerank seo ranking backlink service backlinks google Take care. Jay

Arjuna Chiththananda said...

Thanks for the suggestion Jay, BTW are you the Jay that I used to work with about 5 years back.

Anonymous said...

Can anybody point to some blog posts on this board subject? I want some more detailed info...
Any input will definitely be gratefully appreciated.