文本框textchanged事件始终触发

编程入门 行业动态 更新时间:2024-10-24 08:19:58
本文介绍了文本框textchanged事件始终触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个带有几个文本框和一个Grid-view的表单.有一个名为"Inward Number"的文本框,其文本更改事件始终触发.当我要触发另一个控件的事件时,它仅触发内向号"文本框的文本更改事件.所有其他控件都会发生这种情况.有人可以帮忙吗?

I have a form with a few text-boxes and a Grid-view. There is this one text-box called "Inward Number", whose text-changed event fires all the time. When i want to fire another control's event, it simply fires the text-changed event of the Inward Number text-box. This happens with all of the other controls. Can someone please help?

protected void txtInward_No_TextChanged(object sender, EventArgs e) { a = 'A'; NewRow(); }

我使用了正确的名称,但是仍然会发生此错误.

I have used the correct names, but still this error occurs.

<asp:TextBox ID="txtInward_No" runat="server" Width="220px" CssClass="txtbox" EnableViewState="False" AutoPostBack="True" ontextchanged="txtInward_No_TextChanged"> </asp:TextBox>

新行只会在网格中创建新行.

new row just makes a new row in my grid.

private void NewRow(){int rowIndex = 0;

private void NewRow() { int rowIndex = 0;

if (ViewState["CurrentTable"] != null) { DataTable dtnew = new DataTable(); dtnew = (DataTable)ViewState["CurrentTable"]; DataRow drr = null; if (dtnew.Rows.Count > 0) { for (int i = 1; i <= dtnew.Rows.Count; i++) { TextBox box1 = (TextBox)GridView1.Rows[rowIndex].Cells[2].FindControl("TextBox1"); TextBox box2 = (TextBox)GridView1.Rows[rowIndex].Cells[3].FindControl("TextBox2"); TextBox box3 = (TextBox)GridView1.Rows[rowIndex].Cells[4].FindControl("TextBox3"); TextBox box4 = (TextBox)GridView1.Rows[rowIndex].Cells[5].FindControl("TextBox4"); TextBox box5 = (TextBox)GridView1.Rows[rowIndex].Cells[6].FindControl("TextBox5"); drr = dtnew.NewRow(); if (txtInward_No.Text =="1") { drr["InwardNumber"] = txtInward_No.Text + b.ToString(); } else { drr["InwardNumber"] = txtInward_No.Text + a.ToString(); } drr["Bags"] = box1.Text; drr["GrossWt"] = box2.Text; drr["TareWt"] = box3.Text; drr["NetWt"] = box4.Text; drr["DCBillWt"] = box5.Text; rowIndex++; } dtnew.Rows.Add(drr); ViewState["CurrentTable"] = dtnew; GridView1.DataSource = dtnew; GridView1.DataBind(); } } PrevData(); b++; a++; }

推荐答案

msdn.microsoft/zh-cn/library/system.web.ui.webcontrols.textbox.ontextchanged.aspx

TextBox控件必须在服务器的帖子之间保留一些值,此事件才能正常工作.确保为此控件启用了视图状态.

A TextBox control must persist some values between posts to the server for this event to work correctly. Be sure that view state is enabled for this control.

尝试为TextBox启用ViewState.

Try enabling ViewState for TextBox.

更多推荐

文本框textchanged事件始终触发

本文发布于:2023-11-10 00:44:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573900.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本框   事件   textchanged

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!