| « Prev | Page 1 | Next » |
|
.NET made it "very hard" (i.e. not drag-n-drop'able [sarcasm]) to create control arrays... and, if you use control arrays it wipes out a lot of the WYSIWYG design features - which, with a grid control that's more complex than the space shuttle, is almost required unless you're http://www.datagridgirl.com :)
|
|
Also, you didn't mention the repeated lookups into the Session object - Surely it would have been more sensible to get the user_id out first, rather than look it up 30+ times for the page load and the button click.
|
|
ben,
For i = 1 to 30 Page.FindControl("Grid" & i).user_id = session("user_id") Next Too lazy to typecast, but it works with Explicit off. |
|
Or just loop through all the controls and anything starting with "Grid" will have the user_id set. FindControl might be expensive. (Like calling "session ("user_id")" 5902390390 times isn't.) :)
|
|
Scream if you want to go faster...
dim GridSet as Grid() = {Grid1,Grid2 .... ... dim UserID=Session("User_id") for each GridItem as Grid in GridSet GridItem.User_id=UserID next |
|
I barely coded anything in ASP.NET, so forgive me that stupid question, but does the Session object work like a FIFO list? I'm just trying to get the idea behind the second code snippet.
Because if you're passing Session("user_id") to SaveUserChoices, wouldn't each follow up call on the next grid overwrite the contents each time? Especially since the guy's applying to the same set of contents (Session("user_id")) to all grids in the first snippet. I'm not supposed to get these two snippets, am I? |
|
I'm guessing, but I think session("user_id") is storing a class that is a grab-bag,that these grid controls either stuff their state into (on SaveUserChoices) or grope around and get their stuff (on get). And yeah it's a horrible way to do this.
|
|
In the name of our good lord, what is wrong with that code?
Its very clear to read, anyone can understand, I mean, it is obvious he wants to store the user_id in all his grids. He is probably just following company policies on writing clear and uneficient code. I do that all the time, the more policies one can come up with, the less efficient code you write; you get what you ask for. |
|
He's been bumped to management since that code was written.
|
|
I work with at the place that put out that code, and the we think the guy that wrote it is one of the managers here....
|
|
Well, it may be company policy to review LOC productivity. Unwinding loops is a great way of doing it.
|
Re: re: Hmm .. where to place a button ...
2010-02-03 00:39
•
by
cbhacking
(unregistered)
|
Session(<index>) is a lookup function. In this case, it's using a String index, in the form Session("user_id"). The functionality is "Go to the Session object, look up the field called user_id, and return it". The first snippet does this lookup 30-odd times, each time assigning it to a field of a Grid object. The second snippet does the lookup another 30-odd times, and passes it as a parameter to each Grid object's SaveUserChoices function. It could be re-written as follows: Dim id = Session("user_id")
|
| « Prev | Page 1 | Next » |