[英]I have Button and TextBox in View of ASP.NET MVC - how to send value of Button to TextBox after Click on this Button?
[英]how to create textbox dynamically after click (button)? asp.net
单击按钮后,我试图弄清楚如何动态创建文本框(或其他控件)。 如果将其添加到Page_Load
方法中,我已经编写了一个函数,但是该函数不能与特定按钮相关(单击后)。
另外,我试图了解如何计算点击次数。
.aspx
标记:
<asp:Button ID="addexProductBTN" runat="server" Text="add" onclick="addexProductBTN_Click"/>
<asp:PlaceHolder ID="DynamicControlsHolder" runat="server"></asp:PlaceHolder>
.aspx.cs
代码:
int count = 0;
protected void addnewProductBTN_Click(object sender, EventArgs e)
{
count++;
addControlTB();
}
protected void addControlTB()
{
Table tbldynamic = new Table();
TableCell tc = new TableCell();
TableRow tr = new TableRow();
TextBox NewProdTB = new TextBox();
NewProdTB.ID = "DynamicTextBox";
NewProdTB.Text = "";
tc.Controls.Add(NewProdTB);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
DynamicControlsHolder.Controls.Add(tbldynamic);
}
第一件事与viewstate有关:
TextBox NewProdTB = new TextBox();
NewProdTB.EnableViewState = false;
设置为false和true时,尝试解决行为的变化。
这是有关视图状态行为的文章。
问题的“计数”部分:如果您需要一个在重新加载页面后仍然有效的全局变量,则应尝试使用session object 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.