简体   繁体   English

如何在ASP.NET中使用HTML表格动态添加按钮

[英]How to dynamically add a button using html table in asp.net

I want to add dynamically button in html table. 我想在html表中动态添加按钮。

I created a master page and another subpage. 我创建了一个母版页和另一个子页。

On the sub page, I want to dynamically add a button in html table. 在子页面上,我想在html表中动态添加一个按钮。

This is my code: 这是我的代码:

Button btnSend = new Button();
btnSend.ID = "btnSend";
btnSend.Text = "Send";
btnSend.Click += new System.EventHandler(btnSend_Click);
this.form1.Controls.Add(btnSend);

But I get an error: 但是我得到一个错误:

form1 is not accessible from sub page. 无法从子页面访问form1。

Please help me to dynamically add a button into the html table. 请帮助我将按钮动态添加到html表中。

If you use asp.net then you have no forms. 如果使用asp.net,则没有表格。 So simply insert a button from the toolbox and set buttonName.visible = true or false as you need. 因此,只需从工具箱中插入一个按钮,然后根据需要设置buttonName.visible = truefalse

如果要向子页面添加动态控件,那么我建议您添加一个面板,然后只需使用panel.controls.add(您的按钮)即可。

Do you create the HTML table on codebehind? 您是否在代码隐藏中创建HTML表? If so, you may add the button there. 如果是这样,您可以在此处添加按钮。 If not, you may try putting a Literal there, and fill it with the code for an HTML button if needed. 如果不是,您可以尝试将Literal放在此处,并在需要时用HTML按钮的代码填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM