以编程方式创建按钮 [英] creating button programiticaly

查看:87
本文介绍了以编程方式创建按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个m×n表,每个单元格是一个button.so,我在服务器端创建表和该表单元格的每个按钮,并为evry button添加一个Click事件.因此,我将表添加到占位符控件.事件功能已创建,但是当我单击浏览器上的按钮时,其事件不起作用.我的代码在下面.

i have a m×n table that each cell is a button.so i create table and each button for table cell on server side and i add a Click event for evry button.so i add table to placeholder control. event function is created but when i click on button on browser its event dont work. my code is in below.

{
Table tabletime = new Table();
for (int k = 0; k < intdeadline; k++)//intdeadline is a input fo func
            {
                TableCell tch = new TableCell();
                tch.Text = (Convert.ToDouble(start) + k).ToString() + " - " + (Convert.ToDouble(start) + k + 1).ToString();
                tch.Style.Value = "direction:rtl;float:right;font-size:12px;font-weight:bold";
                tr.Cells.Add(tch);
               for (int j = 0; j < countperhoure; j++)//countperhouese is func input
                {
                    TableCell tc = new TableCell();
                    Button bu = new Button();
                    bu.Text = ((j + 1) + (k * 10)).ToString();
                    bu.Style.Value = "direction:rtl;float:right;font-size:10px;font-weight:bold";
                    bu.Click += new EventHandler(bu_Click);
                    tc.Controls.Add(bu);
                    tr.Cells.Add(tc);
                }
                tr.Style.Value = "border-bottom:1px solid black";
                tabletime.Rows.Add(tr);
            }
            timeprogcreate.Controls.Add(tabletime);
}
void bu_Click(object sender, EventArgs e)
{
        Response.Redirect("MainPage.aspx");//MainPage is other page
}

推荐答案

检查新创建的按钮的Autopostback属性为true还是false.
Check Whether Autopostback Property of newly created buttons true or false.


这篇关于以编程方式创建按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆