Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In ASP.Net code-behind, I can set the controls (e.g. asp:Button) like this below:
C#
void setButtonStyle(Button btn)   {
    if (btn.Enabled)
        btn.Attributes.Add("style", "font-style:italic; font-weight:bold; background-color: #6bb642;");
    else
        btn.Attributes.Add("style", "font-style:normal; font-weight:normal; background-color: #81BEF7;");
}

In this page, there are also a couple of HTML buttons, how can these HTML buttons be set? Thanks.

What I have tried:

How to set HTML Control in code-behind?
Posted
Updated 15-Jul-16 4:15am

Add runat="server" attribute to the HTML element to convert it to a server control.
now you can access the control from codebehind file

few examples:

ASP.NET
<input type="submit" id="btnInputTypeSubmit" runat="server" value="MyButton" />
       <button id="btnHTMLElement" runat="server">Button Control</button>
 
Share this answer
 
Comments
s yu 15-Jul-16 8:37am    
KB: Thanks for your response. My code for the HTML controls is similar to yours. For asp:Button, I can access to the button like void setButtonStyle(Button btn). But for HTML button, what is the type for the HTML button?
Karthik_Mahalingam 15-Jul-16 8:40am    
for btnInputTypeSubmit -> HtmlInputSubmit

for btnHTMLElement -> HtmlButton
s yu 15-Jul-16 10:05am    
In Code-Behind, the HtmlButton type is not recognized. Thanks.
Karthik_Mahalingam 15-Jul-16 10:10am    
Resolve the " using " for it

Right click ->resolve using
add runat="server" to your html
and get the data of it code-behind like :
C#
string x = id of tag.Value;
 
Share this answer
 
v2
Comments
s yu 15-Jul-16 11:14am    
The runat="server" does exist in the html. I have no problem to access to the HTML controls in code-behind. What I need is to have a general method to re-set the style of the HTML controls, in which it is needed to have general type for the HTML controls. Thanks anyway.
s yu 18-Jul-16 8:06am    
Solved by
void setHTMLControlStyle (System.Web.UI.HtmlControls.HtmlTableRow control, string sStyle) {
control.Attributes.Add("style", sStyle);
}
Thanks for your review and response.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900