【发布时间】:2020-05-03 06:30:34
【问题描述】:
在我的 aspx 文件中,我有以下代码:
<asp:PlaceHolder ID="phdHolding" runat="server">
<asp:Label ID="lblWarning" runat="server" Text="" Visible="false" />
<asp:PlaceHolder ID="phdInput" runat="server" Visible="false">
<h3><asp:Label ID="lblArea" runat="server" Text="Area" /></h3>
</asp:PlaceHolder>
</asp:PlaceHolder>
在 (c#) 后面的代码中,我创建了一个添加到 phdInput 的表。该代码的一部分是在表格单元格中创建和填充文本框(和标签)。需要 TextBox 才能调用 TextChanged 上的函数。
decimal amount = Convert.ToDecimal(dc.DataScalar("SELECT Item" + rownr + " FROM Companies WHERE CompanyName='" + coy + "' AND BusinessUnit='" + bu + "'"));
TextBox tb = new TextBox(); tb.ID = "txtAmount" + rownr; tb.Width = 70; tb.Text = amount.ToString("N0");
tb.AutoPostBack = true; tb.TextChanged += new EventHandler(UpdateAmounts);
Label lbl = new Label(); lbl.Text= " " + trow["Unit"].ToString();
TableCell tdamount = new TableCell(); tdamount.Controls.Add(tb); tdamount.Controls.Add(lbl);
tr2.Cells.Add(tdamount);
一切正常,一切都显示在页面上。但是,当文本发生更改并且您在文本框外单击或按“Enter”等时,未达到该功能(已在 VS 中检查)并且 phdInput 变为空白。
我之前使用过这个函数,以及调用它的 TextChanged 方法,没有任何问题,为什么它现在不起作用?
【问题讨论】:
-
您能告诉我们
tr2的定义以及您在表单中添加tr2的时间吗? -
对于行中的第一个单元格: int rownr = Convert.ToInt32(trow["Srl"].ToString());表行 tr2 = 新表行(); tr2.VerticalAlign = VerticalAlign.Top; TableCell tdtype = new TableCell(); tdtype.Text = trow["Type"].ToString(); tdtype.Width = 250; tdtype.HorizontalAlign = HorizontalAlign.Left; tr2.Cells.Add(tdtype);
标签: c# asp.net textchanged