M
Mark Olbert
I just spent several frustrating hours tracking down a subtle problem involving a simple web page. I'm sharing the solution so as to
spare others a similar experience.
The web page has only three controls, all of which are bound to SqlDataSource controls: two dropdowns and a repeater. However, the
contents of the second dropdown depend upon the selection made in the first dropdown, and the contents of the repeater depend upon
the selections made in both dropdowns.
The problem is this: SqlDataSource controls have a connection string property. If you use a different datasource for development
than you do on the production site, you have to change the connection string at some point in the page lifecycle when it runs in the
production environment or the data may not be retrieved.
This is not an unusual situation, and with the old data adapter/dataset load model I handled it by assigning connection strings in
the Page_Load method.
Unfortunately, SqlDataSource controls don't persist their connection strings..so if you're going to change them you need to do so on
every postback. You may be able to do this in the Page_Load method, but to be safe I opt to do it by overriding the OnInitComplete
method (because I believe event processing takes place immediately after OnInitComplete, and the controls must be properly
configured before event handling takes place).
Personally, I think the lack of persistence of connection strings is a nasty little bug that ought to be squashed by Microsoft ASAP.
Sometimes I get the feeling that Microsoft doesn't test ASP.NET in the typical "development environment is different from production
environment scenario". I say this because there are too many little "bolt on" solutions to the "problems" caused by multiple
environments (e.g., having to rewrite the Web.config file). It would be nice if they did.
- Mark
spare others a similar experience.
The web page has only three controls, all of which are bound to SqlDataSource controls: two dropdowns and a repeater. However, the
contents of the second dropdown depend upon the selection made in the first dropdown, and the contents of the repeater depend upon
the selections made in both dropdowns.
The problem is this: SqlDataSource controls have a connection string property. If you use a different datasource for development
than you do on the production site, you have to change the connection string at some point in the page lifecycle when it runs in the
production environment or the data may not be retrieved.
This is not an unusual situation, and with the old data adapter/dataset load model I handled it by assigning connection strings in
the Page_Load method.
Unfortunately, SqlDataSource controls don't persist their connection strings..so if you're going to change them you need to do so on
every postback. You may be able to do this in the Page_Load method, but to be safe I opt to do it by overriding the OnInitComplete
method (because I believe event processing takes place immediately after OnInitComplete, and the controls must be properly
configured before event handling takes place).
Personally, I think the lack of persistence of connection strings is a nasty little bug that ought to be squashed by Microsoft ASAP.
Sometimes I get the feeling that Microsoft doesn't test ASP.NET in the typical "development environment is different from production
environment scenario". I say this because there are too many little "bolt on" solutions to the "problems" caused by multiple
environments (e.g., having to rewrite the Web.config file). It would be nice if they did.
- Mark