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));
        }

    }

     
  • 相关阅读:
    DevExpress之Treelist应用
    空间参考及坐标转换
    ArcGIS API for JavaScript开发环境搭建及第一个实例demo
    SQL中字符串拼接
    Json.net实现方便的Json转C#(dynamic动态类型)对象
    第四章:C#如何生成JSON字符串提交给接口(服务器)
    第三章:C#如何生成JSON字符串?(序列化对象)
    第二章:C#如何解析JSON数据?(反序列化对象)
    Eucalyptus4.0 管理页面介绍
    Eucalyptus常用查询命令
  • 原文地址:https://www.cnblogs.com/bobofsj11/p/1597807.html
Copyright © 2011-2022 走看看