Button bt = new Button(); bt.Location = new Point(x,y); bt.CssClass = "btStyle"; ....
已经动态加载到其他容器的控件,咋改变其属性? Dim Tmp_Picture1 As PictureBox = New PictureBox() Call Draw_WellDepthScale(Tmp_Picture1)'绘图 GeoPic_Picture.Controls.Add(Tmp_Picture1)'加载如何改变其在容器中的位置? Tmp_Picture1.Location = New System.Drawing.Point(100, 30)'不管用
bt.Location = new Point(x,y);
bt.CssClass = "btStyle";
....
Dim Tmp_Picture1 As PictureBox = New PictureBox()
Call Draw_WellDepthScale(Tmp_Picture1)'绘图
GeoPic_Picture.Controls.Add(Tmp_Picture1)'加载如何改变其在容器中的位置?
Tmp_Picture1.Location = New System.Drawing.Point(100, 30)'不管用
<div id="add" runat="server">
这里是自定义的控件
</div>后台:
protected void Page_Load(object sender, EventArgs e)
{
Button btnAdd = new Button();
add.Controls.Add(btnAdd);//在前台添加个按钮
btnAdd.Text = "新添加的按钮";
btnAdd.Click += new EventHandler(btnAdd_Click);//为按钮绑定事件
} void btnAdd_Click(object sender, EventArgs e)
{
Button btnAdd = (Button)sender;
btnAdd.Text = "改变按钮的值";//改变按钮的显示值
}
{
CreateDynaControls();
} private void CreateDynaControls()
{
Control container = Form, c;
int n = (int?)ViewState["num"] ?? 0;
for (int i = 0; i < n; i++)
if (container.FindControl("txt" + i) == null)
container.Controls.Add(new TextBox { ID = "txt" + i }); if ((c = container.FindControl("txt" + n)) != null)
container.Controls.Remove(c);
}
protected void BtnAdd_Click(Object sender, EventArgs e)
{
ViewState["num"] = ((int?)ViewState["num"] ?? 0) + 1;
CreateDynaControls();
}
protected void Btn_Click(object sender, EventArgs e)
{
string result = string.Empty;
foreach( Control ctrl in PlaceHolder1.Controls )
{
if (ctrl.GetType () == typeof (TextBox ))
{
TextBox tb = ctrl as TextBox;
result = result + "," + tb.Text;
}
} }