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

    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;

    public partial class Default3 : System.Web.UI.Page
    {
        
    public bool IsDynamicLoadControl
        
    {
            
    get
            
    {
                
    object dynamic = ViewState["IsDynamicLoadControl"];
                
    return dynamic == null ? false : true;
            }

            
    set
            
    {
                ViewState[
    "IsDynamicLoadControl"= value;
            }

        }

        
    protected override void LoadViewState(object savedState)
        
    {
            
    base.LoadViewState(savedState);
            
    if (IsDynamicLoadControl)
            
    {
                LoadTextBox();
            }

        }


        
    protected void Page_Load(object sender, EventArgs e)
        
    {
            
    if (!IsPostBack)
            
    {
                LoadTextBox();
            }

        }

        
    private void LoadTextBox()
        
    {
            
    for (int i = 0; i < 10; i++)
            
    {
                TextBox input 
    = new TextBox();
                input.ID 
    = "input" + i.ToString();
                
    this.form1.Controls.Add(input);
            }

            IsDynamicLoadControl 
    = true;
        }

        
    protected void Button1_Click(object sender, EventArgs e)
        
    {
            TextBox tb 
    = this.FindControl("input0"as TextBox;
            Page.ClientScript.RegisterStartupScript( 
    this.GetType(),""string.Format("<script>alert('{0}')</script>", tb.Text));
        }

    }

     
  • 相关阅读:
    Oracle RAC的五大优势及其劣势
    Lucene全文检索基础
    oracle手工生成AWR报告方法记录
    log file sync 等侍值高的一般通用解决办法
    log file sync 因为数据线有问题而造成高等侍的表现
    MongoDB实用教程
    1小时学会JQuery
    Ajax+Struts2实现验证码验证功能
    硬件01:门
    关于软件工程的思考15:人和绩效
  • 原文地址:https://www.cnblogs.com/bobofsj11/p/1597807.html
Copyright © 2011-2022 走看看