会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
BB.NET
每天一小步
博客园
首页
新随笔
联系
订阅
管理
asp.net动态添加控件
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
public
partial
class
Default3 : System.Web.UI.Page
{
public
bool
IsDynamicLoadControl
{
get
{
object
dynamic
=
ViewState[
"
IsDynamicLoadControl
"
];
return
dynamic
==
null
?
false
:
true
;
}
set
{
ViewState[
"
IsDynamicLoadControl
"
]
=
value;
}
}
protected
override
void
LoadViewState(
object
savedState)
{
base
.LoadViewState(savedState);
if
(IsDynamicLoadControl)
{
LoadTextBox();
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
!
IsPostBack)
{
LoadTextBox();
}
}
private
void
LoadTextBox()
{
for
(
int
i
=
0
; i
<
10
; i
++
)
{
TextBox input
=
new
TextBox();
input.ID
=
"
input
"
+
i.ToString();
this
.form1.Controls.Add(input);
}
IsDynamicLoadControl
=
true
;
}
protected
void
Button1_Click(
object
sender, EventArgs e)
{
TextBox tb
=
this
.FindControl(
"
input0
"
)
as
TextBox;
Page.ClientScript.RegisterStartupScript(
this
.GetType(),
""
,
string
.Format(
"
<script>alert('{0}')</script>
"
, tb.Text));
}
}
posted @
2009-11-07 10:08
melody&amp;amp;bobo
阅读(
214
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告