我在page_load动态添加checkbox,代码如下:Response.Write("<td   align="+"'"+"center"+"'"+"  width=150> ");
Response.Write("    <asp:CheckBox ID="+"'"+"cb_1"+"'"+" runat="+"'"+"server"+"'"+" width=50 
                  Visible="+"'"+"True"+"'"+" /> "); 
Response.Write("</td> ");
但是界面上看不这个checkbox ,请问这样写有没有问题?

解决方案 »

  1.   

    后台cs代码:
    页面加载时CheckBox cb = new CheckBox();
            cb.ID = "cb_1";
            cb.Visible = true;
            this.Page.Controls.Add(cb);:
      

  2.   

    你那样写有没有问题我不知道。你可以运行起来,然后右键查看源文件,Response.Write()是在页面上注册一段代码,一把会出现在页面的最顶部
      

  3.   

    CheckBox cb = new CheckBox();
            cb.ID = "cb_1";
            cb.Visible = true;
            this.Page.Controls.Add(cb);如果用这个方式添加的话,能不能准确地控制添加到哪个位置?
      

  4.   

    protected void Page_Load(object sender, EventArgs e)
    {
        Button btn = new Button();
        btn.ID = "btn_bank_submit";
        btn.Text = "网上支付";
        btn.Click += new EventHandler(btn_bank_submit_Click);
        this.Controls.Add(btn);
    }
      

  5.   

    加到form1中,form1必须是runat=server        Button btn = new Button();
            btn.Text = "wwwwwwwwwwwww";
            form1.Controls.Add(btn);
      

  6.   

    Response.Write("<td align="+"'"+"center"+"'"+" width=150> ");
    Response.Write(" <input type=checkbox /> "); 
    Response.Write("</td> ");你输出的是html控件,不能写服务器控件的
      

  7.   

    那如果我要往某个 <td>  </td> 中动态添加一个 checkbox ,应该如何写呢?
      

  8.   

    如果用 Response.Write(" <input type=checkbox /> ");  
    那我最后提交的时候,能不能遍历所有的checkbox呢?这个input好象没有ID的吧?
      

  9.   

    Response.Write(" <input type=checkbox name='xxx' value='2222' /> ");   后台
    Request.Params.Get("xxx")得到
      

  10.   

    参考这个,看看是怎样把用户控件动态添加至网页指定的位置:
    http://www.cnblogs.com/insus/articles/2023678.html
      

  11.   

    你这个只能写 html的input标签 后台的.net控件需要 new出来 添加到页面的子控件集合里面去
      

  12.   

    那你就咋页面上定义一个Panel,先固定好Panel的位置,然后在把控件动态的添加的Panel里
    代码://Panel的id为Panel1
    this.Panel1.Controls.Add(cb)
      

  13.   


    请看,你输出的是<asp   控件,你说在页面上能有么
      

  14.   

    前台放PlaceHolder,后台往PlaceHolder中添加Checkbox
      

  15.   

    Response.Write(" <asp:CheckBox ID="+"'"+"cb_1"+"'"+" runat="+"'"+"server"+"'"+" width=50  
      Visible="+"'"+"True"+"'"+" /> ");  
    你这个是服务端的代码直接输出到页面上,不知道会不会自动转为html代码,如果没转的话,那就出不来,因为浏览器不认服务端控件
      

  16.   

    应该用<input  type="checkbox"/>