<script runat=server>
void Page_Load(Object sender , EventArgs e)
{
string strFeatured;
Random RanNum = new Random();
Control ctlControl;
strFeatured = "FeaturedProduct" + RanNum.Next( 1, 3 ) + ".ascx";
ctlControl = LoadControl( strFeatured );
plhFeatured.Controls.Add( ctlControl );
}
</Script>
<html>
<head><title>DisplayFeaturedProduct.aspx</title></head>
<body>
<div style=" height:100%; width:100%">
<div style=" padding-left:200px">
<asp:PlaceHolder id="plhFeatured" Runat="Server" />
</div>
</div>
</body>
</html>
本文介绍了一个使用ASP.NET动态加载不同.ascx用户控件的示例。通过随机选择1到3之间的数字,该示例展示了如何根据不同条件加载不同的用户控件,并将其添加到页面的PlaceHolder中。
532

被折叠的 条评论
为什么被折叠?



