net7:Web用户控件ascx的使用及其动态加载
2021-06-29 12:05
标签:obj int 搬家 box ems return void name lis 原文发布时间为:2008-07-30 —— 来源于本人的百度文章 [由搬家工具导入] Web用户控件test.ascx的源代码: using System; public partial class test : System.Web.UI.UserControl public string Myname protected void Page_Load(object sender, EventArgs e) ---------------------------- 这时你可以看见它多了Myname与N这两个属性,你可以右击控件,属性,然后进行更改,还可以动态加载,代码如下: public partial class _Default : System.Web.UI.Page net7:Web用户控件ascx的使用及其动态加载 标签:obj int 搬家 box ems return void name lis 原文地址:http://www.cnblogs.com/handboy/p/7141544.html
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
{
private string myname;
private int n;
{
get { return myname; }
set { myname = value; }
}
public int N
{
get { return n; }
set { n = value; }
}
{
if (!IsPostBack)
{
Label1.Text = myname;
for (int i = 0; i {
ListBox1.Items.Add(i.ToString());
}
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
{
private ASP.test_ascx t;//页面上必须有一个test这样的控件时,才能有ASP.test_ascx类型
protected void Page_Load(object sender, EventArgs e)
{
Test1.Visible = false;//要动态添加,首先页面上必须有一个这样的控件,所以拉一个,然后不让它显示即可
t = (ASP.test_ascx)LoadControl("~/test.ascx");
t.Myname = "dongtai";
t.N = 3;
PlaceHolder1.Controls.Add(t);
}
}