Re: Nasty DataSourceCotnrol Behavior
- From: Milosz Skalecki [MCAD] <mily242@xxxxxxxxxxxxxxxxx>
- Date: Thu, 1 Mar 2007 01:29:03 -0800
Good morning Mark,
I understand your reasoning, but to be honest i don't find as a problem
because i never use sql data source on my pages as I tend to move all
database access code to separate place. In addtion to what you mentioned -
security is also one of the reasons, plus keeping viewstate as tight as
possible. It's also simple to use <%$ ConnectionString %> (i know that not
the case now) Anyway, as i signalised in last reply, I disagree only at some
point.
Best regards
--
Milosz
"Mark Olbert" wrote:
Milosz,.
Unfortunately, the problem occurs not because of the interaction between controls, but because the ASPNET engine tries to use the
SqlDataSource control as it was configured during development. In other words, this code will fail, even if there is no control
binding to the data source control:
protected void Page_Load( object sender, EventArgs e )
{
if( IsPostBack )
{
}
else
{
// dsrcMatch's connection string was set to something appropriate to the development environment
dsrcMatch.ConnectionString = CorrectConnectionStringForEnvironment
}
}
I found this out when various pages that use the SqlDataSource control blew up on me when I deployed them.
A solution, as I mentioned in the earlier post, is to do this:
protected override void OnInitComplete( EventArgs e )
{
base.OnInitComplete(e);
dsrcMatch.ConnectionString = CorrectConnectionStringForEnvironment
}
This doesn't blow up, because before the data source control gets "activated" in the course of the page load its connection string
is set to the correct value.
You're right about the ViewState holding state information...but every databound page I've ever written needs to access some data
source in the course of its processing in order to put the information into the ViewState (by way of setting control properties,
usually).
Oftentimes that happens after various postbacks, not just on the first postback. For example, consider a page using a Wizard or a
MultiView, each step of which contains databound controls. Not only wouldn't I want to have to databind the controls on the
"invisible" steps, but many times I can't, because I won't know what to fill them with until after the user walks through the first
couple of steps and postbacks.
So I stand by my assertion that it would be much more convenient for the SqlDataSource control to store its connection string in
ViewState or ControlState. Of course, that introduces a security risk, but I bet that could be handled by encrypting the
information.
- Mark
On Wed, 28 Feb 2007 16:23:18 -0800, Milosz Skalecki [MCAD] <mily242@xxxxxxxxxxxxxxxxx> wrote:
Hi Mark,
At some respect i dissagree because connection string is used only when
getting the data from data source. Having data populated, there is no need to
retrieve it again on every postback since viewstate was designed to store all
the details control needs to rebuild itself without acquiring data again and
again. I understand this case is different as combo boxes depend on each
other, but in most scenarios connection string is fixed and set for
IsPostBack == false.
Best regards
- Follow-Ups:
- Re: Nasty DataSourceCotnrol Behavior
- From: Mark Olbert
- Re: Nasty DataSourceCotnrol Behavior
- References:
- Re: Nasty DataSourceCotnrol Behavior
- From: Mark Olbert
- Re: Nasty DataSourceCotnrol Behavior
- Prev by Date: Re: Nasty DataSourceCotnrol Behavior
- Next by Date: Re: Inserting a new row.
- Previous by thread: Re: Nasty DataSourceCotnrol Behavior
- Next by thread: Re: Nasty DataSourceCotnrol Behavior
- Index(es):
Relevant Pages
|