.NET Questions (CLOSED)

Questions and Answers on any aspect of .NET. Now closed.

This discussion group is now closed.

Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day.

The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too.

asp.net question, web service results

hi, new to asp.net but not .net developement. anyway, being in this 'stateless' world of web developement has thrown me for more than a few loops lately.
the other day i was reviewing some code where the webform would call a webservice, populate a gridcontrol with the contents and prompt the user to choose a row.
upon clicking the desired row, the webform would call the webservice *again*, retrieve the same information from before and then iterate thru the results to find the desired row.
this doesn't feel right to me. would a better solution be to cache the results from the first call in session or cache?  or am i not grasping the whole 'stateless' enviroment thing?
state-less dev
Thursday, January 24, 2008
If the initial results are in a gridcontrol, the 'code behind' can react to the click event and determine which row it came from. After you have the row you get to the cell's data. Like so:

Private Sub dtgrdFreightMenu_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dtgrdFreightMenu.RowCommand

If e.CommandName = "btnSelect_RowCommand" Then
            Dim idx As Integer = Integer.Parse(e.CommandArgument)
            Dim dr As GridViewRow = Me.dtgrdFreightMenu.Rows(idx)
            Dim sviaCode As String = dr.Cells(5).Text
        End If
End Sub
KooKoo Kachoo
Thursday, January 24, 2008
> this doesn't feel right to me. would a better solution be to cache the results from the first call in session or cache?

Generally not. The more you cache things on a per-session basis, the worse your application will scale. You also need to find a way to invalidate the cache when the data being cached changes. The right thing to do would be to provide an additional web service that takes the key of the desired row  and returns only that row. If that's not an option, I'd do it the way it was done in the code that you're looking at. I'd only cache the data if I knew that retrieving the whole result every time was creating a serious performance problem.

Key concepts:

1. (Somewhat web specific) Store as little session state as possible.
2. (Not web specific) Measure before you optimize.
Thursday, January 24, 2008
thanks for the comments/advice. 

your advice clcr is spot on..measure then optomize. maybe i have digressed into 'goldplating' but this code really jumped out at me. it didn't feel right...

with koo's approach above, the data is available via the row[]cell[] references...so the 2nd webservice call really isn't needed right?

it just seems like this scenario has to be very common in web development.
state-less dev
Thursday, January 24, 2008

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz