I have a combobox that, when I select different options, launches an UpdatePanel containing a GridView to update with new data that depends on the selected combobox item through Postback AJAX.
Everything generally works fine, except when I:
- Select another entry in the combo box selected to load the page (this is only the first). This causes a gridview update.
- Hit update.
The updated screen is loaded with the first entry in the selected combobox and the corresponding contents for this first element in the gridview. But then the combo box will be changed to the entry that I selected in step 1 above, presumably restored from the viewstate. But gridview is not updated - it shows data for combobox selection by default - so the two are not in sync. If I click in the browser URLs field and press Enter, then just the GETURLs, everything is reset correctly.
I tried adding add EnableViewState="false" ViewStateMode="Disabled"to combobox, but when upgrading the gridview is reset, but the combo returns to a value other than the default. Actually, this seems to be even worse: if I load the page, select another combobox element and click refresh, then choosing the default combined element causes a postback, gets a 200 response, but the gridview is no longer updated - until I clear my a session either by logging out or restarting the server. At least with viewstate enabled, I can restore by selecting different entries in the combo box.
, , , . gridview . AutoPostBack="true", SQL asp:sqldatasource. , Javascript onblur , . , , . enabled enabled = true readonly = false, asp-, Load codebehind, , . , , . -, ASP.NET.
(dsAreaCombo SELECT):
<asp:DropDownList ID="cmbProvince" runat="server" class="form-control dropdown" AutoPostBack="true"
data-placeholder="Choose a Province"
DataSourceId="dsAreaCombo" DataTextField="ProvinceDescription" DataValueField="RegionID">
</asp:DropDownList>
:
<asp:gridview Id="grdPBBBudget"
DatasourceId="dsPBBBudget"
AutoGenerateColumns="false"
DataKeyNames="ParentProductID, SegmentID"
onRowUpdating="grdPBBBudget_RowUpdating"
onRowUpdated="grdPBBBudget_RowUpdated"
onRowDataBound="grdPBBBudget_RowDataBound"
runAt="server">
<columns>
<asp:BoundField datafield="GrandparentProductDescription"
ReadOnly="true" />
...
<asp:templatefield headertext="Accounts">
<itemtemplate>
<asp:TextBox id="Accounts"
text='<%#Eval("Accounts", "{0:F0}")%>'
runat="server"
AutoPostBack="true"
OnTextChanged="Accounts_TextChanged"
onblur="return disable_for_postback(this, true);"
DataFormatString="{0:F0}"
class="inline-input"/>
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmbProvince" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
RowDataBound . TextChanged grd.UpdateRow. RowUpdating e.NewValues. RowUpdated DataBind gridview. dsPBBBudget SELECT .
, viewstate, ?