How to set up programmatic table background during asp.net page launch?

I have an aspx page with one default background color. I need to be able to change it programmatically when a specific switch parameter is selected. I tried to set the table ID field, but I cannot access it in my C # code behind the file.

My source table:

<table id="tblSheet" runat="server" style="border-color: #FF9900; border-style: solid; 
border-width:  thin; width:100%; background-color: #99ccff;" cellspacing="4" 
cellpadding="1">

I do not see the identifier in my intellisense.

Edit:
Now that I see my table in my code, I am trying to change the background color. Here is the code for my radioobuttonlist:

<asp:RadioButtonList ID="rdoStatus" runat="server" AutoPostBack="true"
RepeatDirection="Horizontal" Visible="true"   
OnSelectedIndexChanged="rdoStatus_OnSelectionChanged">
<asp:ListItem Value="181001" Text="Open"/>
<asp:ListItem Value="181002" Text="Closed" />
<asp:ListItem Value="181003" Text="Pending" />
</asp:RadioButtonList>

, , . "", - . "Open or Closed", , .

2:
:

if (rdoStatus.SelectedValue == "181003")
{
  tblSheet.BgColor = "#ff9a9a";
}
else
{
  tblSheet.BgColor = "#99ccff";
}
+3
5

! ( ):

<table id="tblSheet" runat="server" style="border-color: #FF9900; border-style: solid; 
border-width: thin; width:100%;" cellspacing="4" cellpadding="1">

Page_Load, :

tblSheet.Bgcolor = "#99ccff";

Voila! Radobuttonlist , . . !

+2

runat="server"

, .

, :

if (rdoStatus.SelectedValue == "181003")
    {
      tblSheet.Style.Add("background-color", "#ff9a9a");
    }
    else
    {
      tblSheet.Style.Add("background-color", "#99ccff");
    }

, :

if (rdoStatus.SelectedValue == "181003")
{
  tblSheet.CssClass = "default_color"
}
else
{
  tblSheet.CssClass = "other color"
}
+4

, ?
, ?

- "", javascript :

<input type="radio" value="..." name="..." id="..."
    onclick="document.getElementById('tblSheet').style.backgroundColor = '#99ccff';" />

, postbacks , - ( , , ). .

, , javascript . , javascript .

+2

, runat = "server" , , -, , . , , , .

, "" # FF9900, , .

0

As Joel said, JavaScript is the best solution if you only need to change colors, but if you convert the table to a server control (using runat = server in your table or another server control), be sure to use the built-in code block in getElementById to retrieve table identifier because ASP.NET renames the identifier when it displays the page.

In Joelโ€™s example, it would look like this:

<input type="radio" value="..." name="..." id="..."    onclick="document.getElementById('<% =tblSheet.ClientID%>').style.backgroundColor = '#99ccff';" />
0
source

Source: https://habr.com/ru/post/1721429/


All Articles