ASP.NET用户控件的使用

创建用户控件如下:

前台页面代码如下:

View Code
 1 <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Content.ascx.cs" Inherits="WLaw.Vip.Help.Content" %>
2
3
4 <div >
5 <p
6
7       <span>
8   <asp:Label ID="lblTitle" runat="server" Text=""> </asp:Label>
9
10       </span>
11 </p>
12 <asp:Label ID="lblFullContent" runat="server" Text=""> </asp:Label>
13 </div>

 

 服务器端代码:

   

       public HelpInfo hif;
public HelpContentInfo HelpContent;

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
PageInit();
}

}
private void PageInit()
{
if (hif == null)
{
return;
}
lblTitle.Text = hif.Title;
lblFullContent.Text = HelpContent.FullContent;
}

 

使用用户控件

在页面中注册用户控件

<%@ Register  Src="~/Help/Content.ascx" TagName="UserContorl" TagPrefix="USContent" %>

调用用户控件:

 <UC:UserContorl runat="server" ID="LeftProServer1" />

服务端代码:

View Code
 1   protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack)
4 {
5 int HelpId = Convert.ToInt32(Request["hId"]);
6 HelpInfo hp = HelpBiz.Get(HelpId);
7 HelpContentInfo HelpContent = HelpContentBiz.Get(HelpId);
8 USContent1.hif = hp;
9 USContent1.HelpContent = HelpContent;
10
11 _title.InnerText = hp.Title;
12 }
13 }

 


 



posted @ 2011-09-29 13:47  石 磊  阅读(10717)  评论(0编辑  收藏  举报