你好,我想请教你一个再ASP.NET后台代码中实现前台动态添加控件并后台取值的问题!能给我个例子吗?谢谢!
展开全部
前台页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel runat="server" ID="p1"></asp:Panel>
</form>
</body>
</html>
后台页面
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default3 : System.Web.UI.Page
{
PlaceHolder myholder;
TextBox myt ;
protected void Page_Load(object sender, EventArgs e)
{
creatwebcontrol();
}
private void creatwebcontrol()
{
myholder = new PlaceHolder();
myt = new TextBox();
//myt.Height = 20;
//myt.Width = 200;
Button mybutton = new Button();
mybutton.Text = "获取内容";
mybutton.Click+=new EventHandler(mybutton_Click);
this.p1.Controls.Add(myt);
this.p1.Controls.Add(mybutton);
}
public void mybutton_Click(object sender, EventArgs e)
{
Response.Write(myt.Text);
}
}
如果有什么不懂的可以再问我
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Panel runat="server" ID="p1"></asp:Panel>
</form>
</body>
</html>
后台页面
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default3 : System.Web.UI.Page
{
PlaceHolder myholder;
TextBox myt ;
protected void Page_Load(object sender, EventArgs e)
{
creatwebcontrol();
}
private void creatwebcontrol()
{
myholder = new PlaceHolder();
myt = new TextBox();
//myt.Height = 20;
//myt.Width = 200;
Button mybutton = new Button();
mybutton.Text = "获取内容";
mybutton.Click+=new EventHandler(mybutton_Click);
this.p1.Controls.Add(myt);
this.p1.Controls.Add(mybutton);
}
public void mybutton_Click(object sender, EventArgs e)
{
Response.Write(myt.Text);
}
}
如果有什么不懂的可以再问我
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询