MainPage文件:WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="TestMasterPage.WebForm1" enableViewState="False"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:PlaceHolder id="PlaceHolder1" runat="server"></asp:PlaceHolder></form>
</body>
</HTML>
WebForm1.aspx.cs
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 TestMasterPage
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.PlaceHolder PlaceHolder1; private void Page_Load(object sender, System.EventArgs e)
{
//在此处放置用户代码以初始化页面
string controlName = "search.ascx";
UserControl control = (UserControl)LoadControl("~/skins/default/controls/"+ controlName);
control.ID = "ID_" + controlName; PlaceHolder1.Controls.Add(control); Response.Write("only trace..");
}
Web窗体设计器生成的代码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
}
}