如何在代码隐藏中设置HTML控件? [英] How to set HTML control in code-behind?
本文介绍了如何在代码隐藏中设置HTML控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在ASP.Net代码隐藏中,我可以设置控件(例如asp:Button),如下所示:
In ASP.Net code-behind, I can set the controls (e.g. asp:Button) like this below:
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;");
}
在这个页面中,还有几个HTML按钮,这些HTML按钮怎么设置?谢谢。
我尝试过:
如何设置HTML在代码隐藏中控制?
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?
推荐答案
将runat =server
属性添加到HTML元素以进行转换到服务器控件。
现在你可以从代码隐藏文件访问控件
几个例子:
Addrunat="server"
attribute to the HTML element to convert it to a server control.
now you can access the control from codebehind file
few examples:
<input type="submit" id="btnInputTypeSubmit" runat="server" value="MyButton" />
<button id="btnHTMLElement" runat="server">Button Control</button>
将runat =server添加到你的html
并获取代码隐藏的数据,如:
add runat="server" to your html
and get the data of it code-behind like :
string x = id of tag.Value;
这篇关于如何在代码隐藏中设置HTML控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文