OnTextChange Partial Postback not occurring

北战南征 提交于 2020-01-17 07:54:37

问题


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


回答1:


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.




回答2:


Remove the autopostback from the parent and add it to child(your custom one). That will solve the issue. Further, since its a custom control so you are inheriting the properties from your parent. Even if you remove the Autopostback from the custo control, i think it might work as the property is true in its parent, by default.




回答3:


set UpdatePanel Mode="Conditional" and AutoPostBack="True" and enableviewstate="true"

now it will work



来源:https://stackoverflow.com/questions/7612858/ontextchange-partial-postback-not-occurring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!