IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New handling a recursive ASP.Net web page
I have a SearchResults.aspx web page which displays the results of a database search in a grid. The query can either be a Social Security Number, a Member ID number, or the beginning of a Last Name and is passed to this page from a StartSearch.aspx page.

The connection object is declared global for the page. In the Page_Load event the connection is opened, the program retrieves data from the database and then closes the connection.

On this page the boss wants me to add a textbox and button so that the user can enter some other value and perform the search again; in effect, starting over from scratch. However, the global connection object is already closed, and any attempt to re-open it within the ResearchButton_Click event throws an error because the "Object reference not set to an instance of an object."

I can't declare and use a different object since several subroutines rely on the one global connection object.

Can anyone offer me some tips please?

"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from."

-- E.L. Doctorow
New sudo apt-get install php __________ :-P
--

Drew
New Not unless you plan
on paying for the conversion of all code from ASP.Net and VB.Net to it, since we have numerous customers using the .Net framework. It would take more than half a day ...

:-)

"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from."

-- E.L. Doctorow
New Some random ideas.
I don't know ASP programming, nor much about databases.

(I assume you threw the exact error message in Google and looked around to make sure that you don't have an error in your code that is different from what you think. E.g. http://codebetter.co.../06/23/65033.aspx )

From your description, it sounds to me like you can't change the logic much. If your boss only wants the freedom to change one of the search terms on your screen, then you'll have to cache the other parameters, build the query instruction, and jump into the StartSearch page at the appropriate place. Being able to jump into the right place would be difficult if the code wasn't written with this type of usage in mind.

Otherwise, if that's not what he wants, then it sounds like you have to change the logic of the StartSearch page and/or the objects you're passing around.

AIUI, mixing GUI elements with business logic is a bad idea for the reasons illustrated here. The logic is tied down, and you're working on a GUI, but your boss wants you to change the GUI in a way that requires a change in logic. Unless you can change the StartSearch page to make it compatible with the GUI he wants, I think you're going to make the code even more difficult to maintain and extend.

But, it's quite possible that I'm completely wrong, so don't take this as gospel. Good luck!

Cheers,
Scott.
New Re: handling a recursive ASP.Net web page
Is there any logic in Page_Load around the opening of the connection that causes it to not get called on PostBack? This is normally when ResearchButton_Click would get called; on a postback to the same page.
New can you reuse the module for the original search?
on button click just rerun the module?
New Re: handling a recursive ASP.Net web page
Page_load will happen every time the page is loaded. So what you want to do is have ResearchButton_Click setup the values and then call SearchResults.aspx as if it was being called from StartSearch.aspx again.

Jay
New That's what I wanted
It took some time to get over the mental hump of having a page call itself.

Back in the old VB6 world having a subroutine call the Form_Load event was no big deal; however, in the web world calling the Page_Load IS a big deal (you need to provide the two parameters that the system automatically fills in for you). I had to reset a bunch of variables, then reload them into Session variables, and then finally have the code do a "Response.Redirect("page") to call itself from scratch.

Thanks everyone!

"Chicago to my mind was the only place to be. ... I above all liked the city because it was filled with people all a-bustle, and the clatter of hooves and carriages, and with delivery wagons and drays and peddlers and the boom and clank of freight trains. And when those black clouds came sailing in from the west, pouring thunderstorms upon us so that you couldn't hear the cries or curses of humankind, I liked that best of all. Chicago could stand up to the worst God had to offer. I understood why it was built--a place for trade, of course, with railroads and ships and so on, but mostly to give all of us a magnitude of defiance that is not provided by one house on the plains. And the plains is where those storms come from."

-- E.L. Doctorow
New I don't get it (well, I do but,,,)
ASP.Net is designed around the idea of pages posting back to themselves. You actually have to go out of your way to do otherwise.

The difficulty in your situation is if you want to modify those search parameters in the QueryString for each new search. ASP.Net wants to treat a URL with a different QueryString like a new request for the page instead of a postback to the same one (in which case it would preserve and rebuild the state of the page and the event to call server-side in hidden VIEWSTATE form variables), so it doesn't let you just modify the QueryString and postback. You have to instead go through the trouble of rebuilding the QueryString yourself and calling Response.Redirect().
New Yep, it's a hack
I'm sure there is a more ASP.NET style solution that involves reworking the connection object and moving the data pull into it's own subroutine that can be called from both the Page_load and button click event.

Honestly though, even when I was coding ASP.NET, I went out of my way to minimize the use of it's event cycle. It's just adding a layer of obscurement to the web event cycle and exists only to try and make ASP.NET and windows forms have a similar event loop. Which doesn't archive anything, good form coding and good web coding still remain vastly different, because the bottlenecks are in different places and the platform fundamentally different.

Jay
New Re: Yep, it's a hack
I do think there's a misunderstanding by Lincoln of the magic ASP.net is doing behind the scenes here. It's understandable given his desktop VB background. I came at ASP.Net after doing plain old HTML form processing with Perl and CGI, so I knew there had to be something keeping state for me and rebuilding object trees server side and routing "events" via hidden form variables.

But it's definitely geared towards "application" style design rather than "website" design.

PS: The ASP.Net style design would have been to ditch the StartSearch.aspx page and just have a single Search.aspx page that only enables the results grid and does the DB work if there is content in the search textbox.
Expand Edited by altmann March 13, 2009, 01:08:02 AM EDT
     handling a recursive ASP.Net web page - (lincoln) - (10)
         sudo apt-get install php __________ :-P -NT - (drook) - (1)
             Not unless you plan - (lincoln)
         Some random ideas. - (Another Scott)
         Re: handling a recursive ASP.Net web page - (altmann)
         can you reuse the module for the original search? - (boxley)
         Re: handling a recursive ASP.Net web page - (jay) - (4)
             That's what I wanted - (lincoln) - (3)
                 I don't get it (well, I do but,,,) - (altmann) - (2)
                     Yep, it's a hack - (jay) - (1)
                         Re: Yep, it's a hack - (altmann)

Perhaps someone needs to clarify a few items in the process so we can actually complete the process.
62 ms