问题
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