FeaturedProduct.cs代码如下:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;public class FeaturedProduct:UserControl
{
 public string BackColor="lightgreen";
}-------------------------------Featured1.ascx<%@ Inherits="FeaturedProduct"%>
<table width="200"
 cellpadding="10"
 cellspacing="0"
 bgcolor="<%=BackColor%>"><tr>
 <td>
 <h3>Hammers on sale!</h3>
 Quality hammers are now on sale in the hardware department.
 </td>
</tr>
</table>------------------------------------Featured2.ascx<%@ Inherits="FeaturedProduct"%>
<tabel width="200"
 cellpadding="10"
 cellspacing="0"
 bgcolor="<%=BackColor%>"><tr>
 <td>
 <h3>Blenders on sale!</h3>
 See our selection of blenders in the home appliance department.
 </td>
</tr></table>----------------------------DisplayFeaturedProductCodeBehind.aspx
<%@ Page Language="C#"%>
<script Runat=Server>void Page_Load(Object sender,EventArgs e)
{
string strFeatured;
Random RanNum=new Random();
Control ctlControl; strFeatured="Featured"+RanNum.Next(1,3)+".ascx";
ctlControl=LoadControl(strFeatured);
((FeaturedProduct)ctlControl).BackColor="Orange";
plhFeatured.Controls.Add(ctlControl);
}
</script>
<html>
<head><title>DisplayFeaturedProductCodeBehind.aspx</title></head><body><asp:PlaceHolder
 ID="plhFeatured"
 Runat="Server"/></body>
</html>如何将FeaturedProduct.cs编译?

解决方案 »

  1.   

    本来有个是vb.net版的,FeaturedProduct.vb代码如下:Imports System
    Imports System.Web.UI
    Imports System.Web.UI.WebControlsPublic Class FeaturedProduct
    Inherits UserControl
       
    Public BackColor As String = "lightgreen"End Class书上写的是这样编译的。在创建这个类的源代码之后,需要编译它。从命令行执行以下语句可以编译程序中的类:
    vbc /t:library /r:System.dll,System.Web.dll FeaturedProduct.vb
      

  2.   

    csc 你搜索一下这个文件就好了
      

  3.   

    解决了,
    在vs.net 2003 的命令行下:
    csc t:/library /r:System.dll,System.Web.dll FeaturedProduct.cs然后会生成一个FeaturedProduct.dll在根目录建立一个bin目录,将FeaturedProduct.dll   copy 进去。搞定了。
    调试地址:
    www.lybh.com/s/DisplayFeaturedProductCodeBehind.aspx大家进来要分吧。