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 }

 


 



转载于:https://www.cnblogs.com/-ShiL/archive/2011/09/29/ShiL201109291345.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值