Search code examples
c#asp.netuser-controls

OnTextChange Partial Postback not occurring


I have the following code for an OnTextChanged event:

protected void CustomTextBox_OnTextChanged(object sender, EventArgs e)
{
    if (tick.Attributes["class"] == "tick displayBlock")
    {
        tick.Attributes["class"] = "displayNone";
        tick.Attributes.Add("class", "displayNone");
    }
    checkAvailability.Attributes.Add("class", "displayBlock");
    checkAvailability.Attributes["class"] = "displayBlock";
}

And:

<asp:UpdatePanel ID="upMyUpdatePanel" runat="server">
    <ContentTemplate>
        <uc:CustomTextBox ID="txtUserName"
            OnTextChanged="CustomTextBox_OnTextChanged" 
            AutoPostBack="True"
            class="someClass">
        </uc:CustomTextBox> 
    </ContentTemplate>
</asp:UpdatePanel>

So I have the above code works perfectly fine in Chrome, IE 8, 9.

However Firefox 6 doesn't seem to do a partial postback.

Before anyone asks I have bubbled up events ontextchanges and autopostback to be used by my customtextbox instances. You can see how on related question: Exposing and then using OnTextChange Event handler


Solution

  • This issue was being cause by a double AutoPostBack.

    Parent control:

    <uc:CustomTextBox ID="ctbMyTextBox"
                            OnTextChanged="CustomTextBox_OnTextChanged"              
                            AutoPostBack="True"             
                            class="someClass">         
    </uc:CustomTextBox>      
    

    Child Control:

    <asp:UpdatePanel ID="upMyUpdatePanel" runat="server">     
        <ContentTemplate>            
            <uc:CustomTextBoxChild ID="ctbcMyTextBox"
                              OnTextChanged="CustomTextBox_OnTextChanged"              
                              AutoPostBack="True"             
                              class="someClass">         
            </uc:CustomTextBoxChild>      
        </ContentTemplate> 
    </asp:UpdatePanel> 
    

    In the parent control I removed AutoPostBack="True" and this fixed the issue for me.

    If someone can give further explanation as to why a Double AutoPostback can cause this I would be happy to check your answer as correct.