简体   繁体   中英

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. I've tried to put a breakpoint in my code but he doesn't get there so he the event isn't firing 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.

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).

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。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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