今天临时调到一个项目组开发几个用户控件,遇到了这样一个问题,哪位高手指教!调用页面(WebForm1.aspx):<body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <div id="div" runat="server"></div> </form> </body>调用页面后台代码(WebForm1.apsx.cs):private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!this.IsPostBack) { this.div.Controls.Add(new WebUserControl1()); } }用户自定义控件前台页面(WebUserControl1.ascx):无用户自定义控件前台页面(WebUserControl1.ascx.cs):无namespace Test{ using System; using System.Data; using System.Drawing; using System.Web; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; /**//// <summary> /// WebUserControl1 的摘要说明。 /// </summary> public class WebUserControl1 : System.Web.UI.UserControl { private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 if(!this.IsPostBack) { Label lbl=new Label(); Button btn=new Button(); lbl.Text="<input type=radio name=radioChiose value=radio1 runat=server Checked>radio1<input type=radio name=radioChiose value=radio2 runat=server>radio2"; btn.Click+=new EventHandler(this.btnSubmit_Click); btn.Text="submit"; this.Controls.Add(lbl); this.Controls.Add(btn); } } Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } /**//// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器 /// 修改此方法的内容。 /// </summary> private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnSubmit_Click(object sender, System.EventArgs e) { Response.Write(this.Request.Form["radioChiose"]); } }}结果如图:用户自定义控件被执行了两次(进入页面就如此)!凡高手指教! 转载于:https://www.cnblogs.com/stwyhm/archive/2005/11/23/282870.html