Ajax Combobox and UpdatePanel issue
Recently i was working on one of my project found funny thing happening with AJAX Combobox and updatepanel. Combobox had Autopostback set to True and On selecetedIndexChanged event on combobox it was to fetch some information from backend and show it on Label control on page.
Label control was placed under updatepanel. and Async Trigger control was Combobox. While testing i found SelectedIndexChanged event was triggering only for the first time. Than after nothing was happening.
This was happening due Combobox was not placed inside Updatepanel. that means both control has to be placed inside updatepanel
Current Sample
Ajax Combobox SelectedindexChanged event fires only once. when updatepanel is used.I had situtaion where i had to disable Control on change of combobox value.Source control and Destination Control both has to be placed under update panel.
HTML
<asp:UpdatePanel ID="UpdatePanel2" runat="server" updatemode="conditional">
<ContentTemplate>
<ajaxToolkit:ComboBox CssClass="ajaxComboBox" ID="cboCategory" runat="server" TabIndex="1"
AutoCompleteMode="SuggestAppend" AutoPostBack="true"></ajaxToolkit:ComboBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Value is required Category"
Text="*" ControlToValidate="cboCategory"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" updatemode="conditional">
<ContentTemplate>
<asp:Label ID="Label16" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cboCategory" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Label control was placed under updatepanel. and Async Trigger control was Combobox. While testing i found SelectedIndexChanged event was triggering only for the first time. Than after nothing was happening.
This was happening due Combobox was not placed inside Updatepanel. that means both control has to be placed inside updatepanel
Current Sample
Ajax Combobox SelectedindexChanged event fires only once. when updatepanel is used.I had situtaion where i had to disable Control on change of combobox value.Source control and Destination Control both has to be placed under update panel.
HTML
<asp:UpdatePanel ID="UpdatePanel2" runat="server" updatemode="conditional">
<ContentTemplate>
<ajaxToolkit:ComboBox CssClass="ajaxComboBox" ID="cboCategory" runat="server" TabIndex="1"
AutoCompleteMode="SuggestAppend" AutoPostBack="true"></ajaxToolkit:ComboBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Value is required Category"
Text="*" ControlToValidate="cboCategory"></asp:RequiredFieldValidator>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" updatemode="conditional">
<ContentTemplate>
<asp:Label ID="Label16" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cboCategory" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
Code behind
Protected Sub cboCategory_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboCategory.SelectedIndexChanged
Label16.Text = ""
If cboCategory.SelectedIndex <> -1 Then
Dim DM As New DataManager
DM.OpenConnection()
txtLifeAmt.Enabled = DM.GetValue("Select IsLifeMember From mastCategories Where ID=" & cboCategory.SelectedValue, DataManager.ValueType.Boolean)
DM.CloseConnection()
Else
txtLifeAmt.Enabled = False
End If
End Sub
Comments
Post a Comment