【发布时间】:2026-02-19 00:25:01
【问题描述】:
我遇到了动态文本框事件的问题。我得到了其他带有 textchanged 事件的动态文本框,其他的都很好,但是这个永远不会进入事件,属性 AutoPostBack = true,EnabledViewState 也是,EnabledViewTheming 也是,它进入了一个 UpdatePanel,我创建了一个动态触发器。
这是我的代码:
TextBox DescUnit = new TextBox();
DescUnit.ID = "DescUnit_txt" + (No).ToString();
DescUnit.Text = "0.0";
DescUnit.TextChanged += new EventHandler(DescUnit_TextChanged);
DescUnit.AutoPostBack = true;
DescUnit.EnableViewState = true;
DescUnit.EnableTheming = true;
Trgr = new PostBackTrigger();
Trgr.ControlID = DescUnit.ID;
UpdatePanel1.Triggers.Add(Trgr);
Table.Rows[i - 1].Cells[3].Controls.Add(DescUnit);
这是我的活动的代码
protected void DescUnit_TextChanged(object sender, EventArgs e)
{
Descuento_Row.Visible = true;
int i = 1;
foreach (HtmlTableRow Row in Tab.Rows)
{
if (Row.ID != null && String.Compare(Row.ID.Substring(0, 6), "TRDet_") == 0)
{
Detalle = (HtmlTable)(Row.Cells[0].Controls[0]);
if (sender.Equals(Detalle.Rows[1].Cells[3].Controls[0]))
{
TextBox Cantidad = new TextBox();
Clonar(Tab.Rows[i].Cells[1].Controls[0], Cantidad);
TextBox Precio = new TextBox();
Clonar(Tab.Rows[i].Cells[4].Controls[0], Precio);
TextBox DescUnit = new TextBox();
Clonar(Detalle.Rows[1].Cells[3].Controls[0], DescUnit);
TextBox ImpDesc = new TextBox();
Clonar(Detalle.Rows[2].Cells[4].Controls[0], ImpDesc);
ImpDesc_txt.Text = ((Convert.ToDouble(ImpDesc_txt.Text) - Convert.ToDouble(ImpDesc.Text)) + (Convert.ToDouble((Convert.ToDouble(DescUnit.Text) / 100)) * (Convert.ToDouble(Precio.Text) * Convert.ToInt32(Cantidad.Text)))).ToString();
ImpDesc.Text = (Convert.ToDouble((Convert.ToDouble(DescUnit.Text) / 100)) * (Convert.ToDouble(Precio.Text) * Convert.ToInt32(Cantidad.Text))).ToString();
Detalle.Rows[2].Cells[4].Controls.Clear();
Detalle.Rows[2].Cells[4].Controls.Add(ImpDesc);
}
i = i + 2;
}
}
}
但永远不要进入它。谁能帮帮我?
【问题讨论】:
-
您确定事件没有触发,而不是该方法没有按应有的方式工作吗?
-
是的,我确定,我正在调试,但它没有触发
-
尝试删除 ID...看看是否可行并告诉我
-
您是否使用正确的文本框进行测试?代码对我来说似乎没问题。
-
@kumaDK 这就是我的想法。因为 ID 上没有标识(文本框有一个 ID,但该方法不检查它,所以它通过了)。然而这只是一个理论