动态添加web控件
来源:互联网 发布:linux 查看ntp 编辑:程序博客网 时间:2024/04/28 06:24
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace DynamicCreateControl
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1;
private TextBox textBox = new TextBox();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
his.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
textBox.Text = "00001";
textBox.ID = "txtBox";
this.PlaceHolder1.Controls.Add( textBox );//
将 PlaceHolder 控件用作存储动态添加到网页的服务器控件的容器。PlaceHolder 控件不产生任何可见输出并且只能用作网页上其他控件的容器。可以使用 Control.Controls 集合添加、插入或移除 PlaceHolder 控件中的控件。//
}
private void Button2_Click(object sender, System.EventArgs e)
{
this.Label1.Text =Request["txtBox"];
}
}
}
2、
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
HtmlButton myButton = new HtmlButton();
myButton.InnerText = "Button 1";
PlaceHolder1.Controls.Add(myButton);
myButton = new HtmlButton();
myButton.InnerText = "Button 2";
PlaceHolder1.Controls.Add(myButton);
myButton = new HtmlButton();
myButton.InnerText = "Button 3";
PlaceHolder1.Controls.Add(myButton);
myButton = new HtmlButton();
myButton.InnerText = "Button 4";
PlaceHolder1.Controls.Add(myButton);
}
</script>
</head>
<body>
<form runat="server">
<h3>PlaceHolder Example</h3>
<asp:PlaceHolder id="PlaceHolder1"
runat="server"/>
</form>
</body>
</html>
完
- 动态添加web控件
- Web动态添加控件
- 动态添加web控件
- 动态添加WEB控件,点控件获取动态添加的控件
- vs2005 web application页面动态添加控件获取属性值
- 利用JS在web前段动态添加控件
- 动态添加控件
- 动态添加控件
- 动态添加用户控件
- 动态添加控件事件
- 动态控件添加问题
- 动态添加控件
- 动态添加控件TextBox2
- 动态添加控件
- HTML 动态添加控件
- 动态添加控件
- JavaScript 动态添加控件
- 动态添加控件注意事项
- Asp.net源码每周更新之五.一后(5.8-5.12)
- 使用ServerVariables 获得ASP.NET环境变量
- Eclipse 3.0.1插件方案(Java版)
- Grails环境部署开发
- 开始进入spring+hibernate!!1
- 动态添加web控件
- 变量b_mbrd意义
- Grails教程
- 动态生成sql语句
- 心情···
- C#中用“橡皮条”法绘图和重绘
- WebServices入门
- BUTTON事件监听器-经典
- Java数据类型转换