用户控件为什么会被执行两次?(高手指教)

该博客为转载内容,转载自https://www.cnblogs.com/stwyhm/archive/2005/11/23/282870.html ,涉及Java和UI方面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天临时调到一个项目组开发几个用户控件,遇到了这样一个问题,哪位高手指教!
调用页面(WebForm1.aspx):
None.gif<body MS_POSITIONING="GridLayout">
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<div id="div" runat="server"></div>
None.gif        
</form>
None.gif    
</body>
调用页面后台代码(WebForm1.apsx.cs):
None.gifprivate void Page_Load(object sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
ExpandedSubBlockStart.gifContractedSubBlock.gif
            if(!this.IsPostBack) dot.gif{
InBlock.gif                
this.div.Controls.Add(new WebUserControl1());
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }
用户自定义控件前台页面(WebUserControl1.ascx):无
用户自定义控件前台页面(WebUserControl1.ascx.cs):无
None.gifnamespace Test
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif    
using System;
InBlock.gif    
using System.Data;
InBlock.gif    
using System.Drawing;
InBlock.gif    
using System.Web;
InBlock.gif    
using System.Web.UI.WebControls;
InBlock.gif    
using System.Web.UI.HtmlControls;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
///        WebUserControl1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebUserControl1 : System.Web.UI.UserControl
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
ExpandedSubBlockStart.gifContractedSubBlock.gif
            if(!this.IsPostBack) dot.gif{
InBlock.gif                Label lbl
=new Label();
InBlock.gif                Button btn
=new Button();
InBlock.gif                lbl.Text
="<input type=radio name=radioChiose value=radio1 runat=server Checked>radio1<input type=radio name=radioChiose value=radio2 runat=server>radio2";
InBlock.gif                btn.Click
+=new EventHandler(this.btnSubmit_Click);
InBlock.gif                btn.Text
="submit";
InBlock.gif                
this.Controls.Add(lbl);
InBlock.gif                
this.Controls.Add(btn);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
///        设计器支持所需的方法 - 不要使用代码编辑器
InBlock.gif        
///        修改此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
private void btnSubmit_Click(object sender, System.EventArgs e) dot.gif{
InBlock.gif            Response.Write(
this.Request.Form["radioChiose"]);
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
结果如图:
11.JPG
用户自定义控件被执行了两次(进入页面就如此)!凡高手指教!

转载于:https://www.cnblogs.com/stwyhm/archive/2005/11/23/282870.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值