简体   繁体   English

C# - TextBox TextChanged事件未触发

[英]C# - TextBox TextChanged event not firing

I'm currently working on a project at work and for some reason the textchanged event of my textbox isn't firing. 我正在开发一个正在工作的项目,由于某种原因,我的文本框的textchanged事件没有被触发。 I've tried to put a breakpoint in my code but he doesn't get there so he the event isn't firing imo. 我试图在我的代码中设置一个断点,但他没有到达那里,所以他的事件并没有触发imo。

<FooterTemplate>
                <asp:TextBox ID="TextBoxSiteAlias" runat="server" AutoPostBack="true" OnTextChanged="TextBoxSiteAlias_TextChanged"></asp:TextBox>
                <ajaxToolkit:AutoCompleteExtender
                                    runat="server" 
                                    id="AutoCompleteExtenderSiteAlias" 
                                    targetcontrolid="TextBoxSiteAlias"
                                    servicemethod="GetSiteAliasList"
                                    minimumprefixlength="2" 
                                    completioninterval="1000"
                                    enablecaching="true"
                                    completionsetcount="12" />
            </FooterTemplate>

This is my FooterTemplate in my Gridview. 这是我的Gridview中的FooterTemplate。

protected void TextBoxSiteAlias_TextChanged(object sender, EventArgs e)
    {
        string query = @"select distinct (isnull([site_address1], '')
                            +isnull([site_address2], '')
                            +isnull([site_address3], '')
                            +isnull([site_address4], '')
                            +isnull([site_address5], '') ) as 'Site_adresse' ,
                          city,
                          country,
                          [site_id] as 'siteID'
                          FROM [Henkel].[dbo].[tbl_Henkel_site_info_upload]
                          WHERE site_id = '" + ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteAlias")).Text + "'";
        conn.Open();
        SqlCommand cmd = new SqlCommand(query, conn);
        SqlDataReader myReader = cmd.ExecuteReader();
        DataTable myTable = new DataTable();
        myTable.Load(myReader);
        conn.Close();
        if (myTable.Rows.Count > 0)
        {
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteAddress")).Text = Convert.ToString(myTable.Rows[0]["Site_adresse"]);
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteCity")).Text = Convert.ToString(myTable.Rows[0]["city"]);
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteCountry")).Text = Convert.ToString(myTable.Rows[0]["country"]);
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxIBSSiteID")).Text = Convert.ToString(myTable.Rows[0]["siteID"]);
        }
        else
        {
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteAddress")).Text = "";
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteCity")).Text = "";
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxSiteCountry")).Text = "";
            ((TextBox)GridView1.FooterRow.FindControl("TextBoxIBSSiteID")).Text = "";
        }
    }

This is the function that should be called as soon as the dedicated textbox looses focus. 这是在专用文本框失去焦点时应立即调用的函数。

I've been searching for a reason on many forums but all those replies indicated that the textbox needs the AutoPostBack property (which mine has). 我一直在许多论坛上寻找原因,但所有这些回复都表明文本框需要AutoPostBack属性(我的有)。

Small notice: I have the same project (with all the same functionalities for another deal of our company and in that project it works fine. I have copied that projects code to the new project and changed all the queries + connectionstrings) 小通知:我有相同的项目(对于我们公司的另一笔交易具有所有相同的功能,并且在该项目中它工作正常。我已将项目代码复制到新项目并更改了所有查询+连接字符串)

Hopefully someone can help me on this? 希望有人可以帮助我吗? :) :)

Thanks a lot 非常感谢

Kevin 凯文

确保将CausesValidation设置为false。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM