DEV Environment: VS 2005 (WAP Project), DNN 4.3.4, IIS 6 on Win-XP Pro.
I have an existing module that contains a View Control (abcView.ascx) and an Edit Control (abcEdit.ascx). All is working find but the client now wants to add search capability to the abcView control that will allow the end user to "filter" the records contained in the data grid. "Should be easy enough" I said to myself. Well that should have been the first sign of what I was getting myself into... Without tryingto detail the entire code base let me explain where I am and the problem.
The original view form was using a GridView with an associated ObjectDataSource (ODS). The ODS was bound to the "List..." Method of the Controller. All was working fine. Now for the "Easy enough" modifications...
First off, let me say I'm trying to train myself into thinking "re-usable controls" so I figured a search control would be the way to go. Then I could drop the "Search Control" on the View form, tweak the ODS andmove right along. With that in mind here is what I did... Keep in mind because of the problem I've been having it's not in a "reusable state" as of yet. Once I get it working I will (hopefully) "refactor" it into a reusable control.
1. I added other methods to the SQLDataProvider, DataProvider and Controller to do a list using passed in parameters.
2. Made another user control "abcSearch" that has the text boxes for the user to enter their search criterial. In the "abcSearch" control there is a method "GetDataSource" that evaluates the user input and determines if the "ListAll..." or "ListFIltered..." method needs to be used. On intial load the search criteria hasn't been entered yet so the "GetDataSource" method executes the "ListAll..." method.
3. I changed the ODS to bind to the "GetDataSource method" of the "abcSearch" control.
Now the problem...
On initial load of the form the GridView is populated with all records as it should. After entering the search criteria and clicking "Search" the GridView is still populating all records. Initially I thought it was a postback problem and implemented saving and loading the select criterial to the ViewState but that didn't solve the problem.
After tracing program execution here is what I'm seeing... The search criteria is indeed saved to the ViewState when the user clicks "Search" but gets "wiped Out" somewhere along the line. I started tracing through all the functions and found that the following functions are getting called in the following order. NOTE: abcView.ascx is the main view form and abcSearch is the "sub-form", the user control that cointains the search functionality and is embedded on the main view form.
1. abcSearch.ascx - Page_Init function (ViewState intact).
2. abcView.ascx - Page_Init function (ViewState intact).
3. abcView.ascx - Page_Load function (ViewState intact).
4. abcSearch.ascx - Page_Load function (ViewState intact).
5. Default.aspx - Pre_Render function (ViewState is nothing!!!!!).
... the GridView is displayed with all records.
I think I'm missing something. Any suggestions would be greatly appreciated!!
Chuck R.