如何通过aspx代码中的request.form [" x"]方法设置控件的CSS atyle属性? [英] How set CSS atyle attributes of controls via request.form["x"] method in aspx code behind?
问题描述
我想通过
Request.Form [ x]
方法.cs代码,runat =server是为那些控件设置的,它们在.cs的intellisense中是已知的并且它们没有找不到
form1.FindControl( x)
并将它们转换为
HtmlInputText
因为我的原因,但我想用另一种语法设置CSS样式。
谢谢你任何建议
我尝试过:
HtmlInputText intex = FindControl ( txtrelat0)作为的HtmlInputText;
字符串文本=的Request.Form [ txtrelat0]的ToString();
添加asp面板中的控件
< ASP:面板 ID = panel1 runat = 服务器 >
< asp:TextBox runat = server ID = txt1 / >
< span class =code-keyword>< inputtype = text runat = server id = txt2 / >
< / asp:Panel >
找到控件并施放它
var txt1 = panel1.FindControl( txt1) as TextBox; // asp textbox
txt1.Style.Add( background-color, 橙跨度>);
var txt2 = panel1.FindControl( txt2) as HtmlInputText; // input type = text
txt2.Style.Add( background-color, 蓝色跨度>);
I want set CSS style attributes of some controls (like input text) just by
Request.Form["x"]
method in aspx page .cs code ,runat="server" is set for that controls and them is known in intellisense of .cs and them didn't find by
form1.FindControl("x")
and convert them to
HtmlInputText
for some my reason but i want set their CSS style in another syntax.
Thanks for any suggestion
What I have tried:
HtmlInputText intex = FindControl("txtrelat0") as HtmlInputText;
string text=Request.Form["txtrelat0"].ToString();
Add the controls in an asp panel
<asp:Panel ID="panel1" runat="server"> <asp:TextBox runat="server" ID="txt1" /> <input type="text" runat="server" id="txt2" /> </asp:Panel>
find the control and cast it
var txt1 = panel1.FindControl("txt1") as TextBox; // asp textbox txt1.Style.Add("background-color", "orange"); var txt2 = panel1.FindControl("txt2") as HtmlInputText; // input type = text txt2.Style.Add("background-color", "blue");
这篇关于如何通过aspx代码中的request.form [" x"]方法设置控件的CSS atyle属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!