对于输入的相同值,未在选项卡上触发Textchanged事件 [英] Textchanged event not firing on tab for same value entered

查看:47
本文介绍了对于输入的相同值,未在选项卡上触发Textchanged事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我已将autopostback属性设置为true。在textchanged事件上,我写了一些代码。当我第一次输入值ans按tab然后textchanged事件被触发,但第二次当我输入一些相同的值并按Tab键或只是输入tab然后TextChenged事件没有被触发。

请提供我的解决方案



这是我的代码:

.aspx代码:



 <   asp:TextBox     ID   =  txtRegNo2    runat   =  server    CssClass   =  txtbox    TabIndex   =  81      onBlur   =  javascript:CheckRegistrationNo(1, 3,这个    AutoPostBack   =   True    ontextchanged  < span class =code-keyword> =  txtRegNo2_TextChanged   工具提示  =  R2必须为1到3个字符    MaxLength   =  3 >  <   / asp:TextBox  >  









C#代码:

  protected   void  txtRegNo2_TextChanged( object  sender,EventArgs e)
{
try
{
if ((txtRegNo1.Text!= )&& (txtRegNo2.Text!= ))
{
pc.LicensePlateOne = txtRegNo1.Text;
pc.LicensePlateTwo = txtRegNo2.Text;


DataTable dt = new DataTable();

dt = hd.GetRTO_Location(pc);

if (dt.Rows.Count > 0
{
ddlRegLoc.SelectedValue = dt.Rows [ 0 ] [ ID]。ToString();
ddlRegLoc.Enabled = false ;

pd.ID = 3 ;
pd.ProductId =会话[ ProductId]。ToString();
pd.RegLocationId = ddlRegLoc.SelectedValue;

DataTable dtZone = new DataTable();
dtZone = hd.GetLocationaDetails(pd);
if (dt.Rows.Count > 0
{
ddlZone.DataTextField = dtZone.Columns [ 描述]的ToString();
ddlZone.DataValueField = dtZone.Columns [ ID]。ToString();
ddlZone.DataSource = dtZone;
ddlZone.DataBind();
}
}
txtRegNo3.Focus();
}
else
{
ddlRegLoc.SelectedValue = 0;
ddlRegLoc.Enabled = true ;
}
}
catch (SqlException sqlEx)
{
if (sqlEx.Number == -2)
{
string error = sqlEx.Message;
ErrorLogs(错误);
Alert.Show( 超时发生。请稍后再试);
}
}
catch (例外情况)
{
string error = ex.Message;
ErrorLogs(错误);
}
}

解决方案

这就是它的工作原理,只有文字更改事件才能获得如果您的文本被更改,则触发,如果您第一次输入abc并且第二次再次输入abc,则ASP.Net将比较最后一个值与此新值(如果两者相同)则不会触发文本更改事件。

Hi All,

I have set autopostback property true. And on textchanged event I've written some code. When 1st time I enters a value ans press tab then textchanged event is getting fired, but second time when I enters some same value and press tab or just enters tab then TextChenged event is not firing.
Please provide me solution

Here is my code:
.aspx code:

<asp:TextBox ID="txtRegNo2" runat="server" CssClass="txtbox" TabIndex="81"  onBlur="javascript:CheckRegistrationNo(1,3,this)" AutoPostBack="True" ontextchanged="txtRegNo2_TextChanged" ToolTip="R2 must be 1 to 3 characters" MaxLength="3"></asp:TextBox>





C# code:

protected void txtRegNo2_TextChanged(object sender, EventArgs e)
  {
      try
      {
         if ((txtRegNo1.Text != "") && (txtRegNo2.Text != ""))
          {
              pc.LicensePlateOne = txtRegNo1.Text;
              pc.LicensePlateTwo = txtRegNo2.Text;


              DataTable dt = new DataTable();

              dt = hd.GetRTO_Location(pc);

              if (dt.Rows.Count > 0)
              {
                  ddlRegLoc.SelectedValue = dt.Rows[0]["ID"].ToString();
                  ddlRegLoc.Enabled = false;

                  pd.ID = 3;
                  pd.ProductId = Session["ProductId"].ToString();
                  pd.RegLocationId = ddlRegLoc.SelectedValue;

                  DataTable dtZone = new DataTable();
                  dtZone = hd.GetLocationaDetails(pd);
                  if (dt.Rows.Count > 0)
                  {
                      ddlZone.DataTextField = dtZone.Columns["Description"].ToString();
                      ddlZone.DataValueField = dtZone.Columns["ID"].ToString();
                      ddlZone.DataSource = dtZone;
                      ddlZone.DataBind();
                  }
              }
              txtRegNo3.Focus();
          }
          else
          {
              ddlRegLoc.SelectedValue = "0";
              ddlRegLoc.Enabled = true;
          }
      }
      catch (SqlException sqlEx)
      {
          if (sqlEx.Number == -2)
          {
              string error = sqlEx.Message;
              ErrorLogs(error);
              Alert.Show("Timeout occured. Please try later");
          }
      }
      catch (Exception ex)
      {
          string error = ex.Message;
          ErrorLogs(error);
      }
  }

解决方案

Well this is how it works, text change event only get fired if your text is changed, if you entered "abc" first time and second time you have entered "abc" again then ASP.Net will compare last value with this new value if both are same then text change event will not get fired.


这篇关于对于输入的相同值,未在选项卡上触发Textchanged事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆