zoukankan      html  css  js  c++  java
  • asp.net 动态添加多个用户控件

    动态添加多个相同用户控件,并使每个用户控件获取不同的内容。

    用户控件代码: 
    代码WebControls 

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    namespace xuyuanwang.myControl 

    public partial class Lablexuyuan : System.Web.UI.UserControl 

    string a = "ok"; 
    public string A 

    set 

    a = value; 

    get 

    return a; 


    protected void Page_Load(object sender, EventArgs e) 

    Label1.Text = A; 


    aspx页面代码: 

    public partial class WebForm1 : System.Web.UI.Page 

    protected void Page_Load(object sender, EventArgs e) 


    protected void Button1_Click(object sender, EventArgs e) 

    myControl.Lablexuyuan ctl = (myControl.Lablexuyuan)Page.LoadControl("myControl/Lablexuyuan.ascx"); 
    ctl.A = this.TextBox1.Text; 
    ArrayList list = addl(ctl); 
    for (int i = 0; i < list.Count; i++) 

    myControl.Lablexuyuan ctl2 = (myControl.Lablexuyuan)list[i]; 
    this.UpdatePanel1.ContentTemplateContainer.Controls.Add(ctl2); 


    private System.Collections.ArrayList addl(myControl.Lablexuyuan l) 

    System.Collections.ArrayList list = null; 
    if (Session["a"] != null) 

    list = (ArrayList)Session["a"]; 

    else 

    list = new ArrayList(); 

    list.Add(l); 
    Session["a"] = list; 
    return list; 

  • 相关阅读:
    js数组的常见操作( push、pop、unshift、shift、splice、concat、 join)的用法
    js json对象与字符串转换
    js回调函数(callback)
    Array数组 [] 遍历方法
    65.rem布局详解(一图流)
    关于内存泄漏
    JS精粹知识点和我的解释
    再谈布局2-Flex布局
    input和button不同高 和 rem
    正则表达式学习
  • 原文地址:https://www.cnblogs.com/sjqq/p/6409614.html
Copyright © 2011-2022 走看看