问题
I have an asp.net page which has amoungst some basic labels etc, and an updatepanel containing a dynamic list of UserControls. Each control has its own UpdatePanel, and basic controls. I have hatched together a collaps/expand feature for these controls and has been working fine to date.
To make the page more efficient I have been working to 'Async-ify' the heavy data processing that happens during load, to display in these fields and user controls.
After all of these changes everything still works fine (including a massive performance boost), except one thing - the collapse/expand no longer works. The limited data viewable in collapsed mode' has updated fine.
Reverting back to a non async call for the data, and everything works fine again, but slow again.
It is like they are constantly forced back to their original default state (collapsed), on each postback, triggered by the collapse/expand button. But nothing has changed from this perspective. I have literally only changed the data call to await async instead of non-async, which as i overstate, is fine for everything except this issue.
I can post any code, but not sure what is relevant. The only change I have made is as follows:
Protected Async Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Update()
End Sub
Private Async Function Update() As Task
Dim AController As New CIP_WS.ARFController
ARF = AController.GetARFWithResults(Client.ClientID, PRN, Nothing, StartTime, EndTime, CIP_WS.LabResultController.InequalityModes.AsIs)
PrintBasic()
PrintSPC()
PrintPhotos()
PrintResults()
PrintHistoricEdits()
End Function
Above works fine - non async
Protected Async Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RegisterAsyncTask(New PageAsyncTask(Function() Update()))
End Sub
Private Async Function Update() As Task
Dim AController As New CIP_WS.ARFController
Dim ARFTask As Task(Of CIP_WS.ARF) = AController.GetARFWithResultsAsync(Client.ClientID, PRN, Nothing, StartTime, EndTime, CIP_WS.LabResultController.InequalityModes.AsIs)
ARF = Await ARFTask
PrintBasic()
PrintSPC()
PrintPhotos()
PrintResults()
PrintHistoricEdits()
End Function
Above, everything works fine, except usercontrol's not persisting their updated collapsed/expanded state.
Any help most appreciated
EDIT _____
Expand/Collaps method, as requested:
Partial Class wucLabResultPack
Inherits System.Web.UI.UserControl
Private _Expanded As Boolean
Public Property Expanded() As Boolean
Get
Return _Expanded
End Get
Set(ByVal value As Boolean)
_Expanded = value
ViewState("Expanded") = _Expanded
UpdateExpandPanel()
End Set
End Property
Protected Sub imgExpand_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgExpand.Click
ToggleExpanded()
End Sub
Private Sub ToggleExpanded()
Expanded = Not Expanded
End Sub
Private Sub UpdateExpandPanel()
If Expanded Then
pnlDetail.Visible = True
imgExpand.ImageUrl = "Images/Shrink.png"
Else
pnlDetail.Visible = False
imgExpand.ImageUrl = "Images/Expand.png"
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Expanded = CInt(ViewState("Expanded"))
End If
End Sub
来源:https://stackoverflow.com/questions/44285371/asp-net-updatepanel-with-usercontrols-and-page-level-async-method