动态产生一个TextBox,并使输入的文本靠右对齐
动态产生一个TextBox控件,还要在这个文本框输入的文本是靠右对齐。
protected void Page_Load(object sender, EventArgs e)
{
//new一个TextBox
TextBox textBox = new TextBox();
//添加样式,靠右对齐
textBox.Attributes.CssStyle.Add("text-align", "right");
//把TextBox加入至form中去
this.form1.Controls.Add(textBox);
}
{
//new一个TextBox
TextBox textBox = new TextBox();
//添加样式,靠右对齐
textBox.Attributes.CssStyle.Add("text-align", "right");
//把TextBox加入至form中去
this.form1.Controls.Add(textBox);
}
网页在run的效果:
ViewSource,可以看到它产生的html,20行:
View Code
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head><title>
5
6 </title></head>
7 <body>
8 <form method="post" action="Default.aspx" id="form1">
9 <div class="aspNetHidden">
10 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZHjRxz8XqFAWqXCeDi/Ui9Mjrk+kijl2/e8fNFCJY+nM" />
11 </div>
12
13 <div class="aspNetHidden">
14
15 <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKOw4z/CAKfwImNCyChir4mZOY3TaHN2tqxCujAQDmy+q3MQPt3fFXNFrkW" />
16 </div>
17 <div>
18
19 </div>
20 <input name="ctl02" type="text" style="text-align:right;" /></form>
21 </body>
22 </html>
2
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head><title>
5
6 </title></head>
7 <body>
8 <form method="post" action="Default.aspx" id="form1">
9 <div class="aspNetHidden">
10 <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZHjRxz8XqFAWqXCeDi/Ui9Mjrk+kijl2/e8fNFCJY+nM" />
11 </div>
12
13 <div class="aspNetHidden">
14
15 <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKOw4z/CAKfwImNCyChir4mZOY3TaHN2tqxCujAQDmy+q3MQPt3fFXNFrkW" />
16 </div>
17 <div>
18
19 </div>
20 <input name="ctl02" type="text" style="text-align:right;" /></form>
21 </body>
22 </html>