Question

I have a simple webcontrol.ascx with an listview and 2 Integer fields (show nbr. of certain elements). The Listview gets filled from an asp:ObjectDataSource.

My Problem is that both the listview and my 2 integer values need access to the same database table and I really dont want to make that call twice (Inside the Page_Load for the 2 fields and inside the SelectMethod for the ObjectDataSource)

The Problem is that I dont see a simple way for the two methods (Page_Load and SelectMethod) to exchange any data (with local properties for example).

private mydata As List(of ...)

protected Sub Page_Load(...) Handles Me.Load
    mydata = DbManager.HeavyCall(...)
    literalValueA.Text = (From i in mydata ..... ).Count
    literalValueB.Text = (From i in mydata ..Where ... ).Count
End Sub

' SelectMethod for asp:ObjectDataSource
public Function GetData( ... ) As List(of ...)

    mydata.DoSomething(...)  ' mydata is Nothing here...

end Function

I hope someone can tell me a good solution (preferable without external cache..) of how to exchange data between the two methods..

Was it helpful?

Solution

The sad solution is: dont use the asp:ObjectDataSource...

Now Im using the asp:LinqDataSource wich provides a 'selecting'-event from where I can modify the Controls on my frontend.

' Selecting-Event from my LinqDataSource
private Sub myLinqDataSource_Selecting(sender .., e .. ) Handles myLinq..Selecting

    dim mydata = DbManager.HeavyCall(..)
    literalValueA.Text = (From i in mydata ..... ).Count        ' works
    literalValueB.Text = (From i in mydata ..Where ... ).Count  ' works

    e.Result = mydata

End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top