stop databind for invisible controls?

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi,

I have a page where according to the mode of use, different controls are
visible.

I had assumed that Page.DataBind() would only bind visible controls, but
apparently not.

Do I have to write my own Page.DataBind() to step through and only bind to
visible controls, or is there a better solution?

Thanks
Martin
 
Hi Martin,
that Page.DataBind() would only bind visible controls, but
apparently not.

Of course not !!, what if you are using an invisible control to hold a
value, or if you have some client side logic that make them visible after
some event in the client?
Do I have to write my own Page.DataBind() to step through and only bind to
visible controls, or is there a better solution?

If you want to not bind certains controls, then you should not declare a
bind on them in the aspx , just create a method that you call as you need.

Cheers,
 
I have grouped the controls into panels, and call databind on the panels as
required.

I would use a bespoke viewstate key value pair to store "invisible" data. -
not an invisible control.

I prefer to set control binding up in the design view of aspx page as it
saves on potential error.

Martin
 
... or if you have some client side logic that make them visible after
some event in the client?
If you set Visible=false, the control won't be rendered to the client in
the first place. The client won't find it.

Eliyahu
 
Martin said:
Hi,

I have a page where according to the mode of use, different controls are
visible.

I had assumed that Page.DataBind() would only bind visible controls, but
apparently not.

Do I have to write my own Page.DataBind() to step through and only bind to
visible controls, or is there a better solution?

There have been many good suggestions in this thread, so let me ask: why is
it a problem for you if DataBind is called on the invisible controls, and
how much of a problem is it?
 
The data source is not available in some scenarios, so a runtime error would
occur on databind. As I have said, I've reduce the scope of the databind,
according to what is visible, with my own Page level databind routine. So
it's not a great problem
 
Martin said:
The data source is not available in some scenarios, so a runtime error would
occur on databind. As I have said, I've reduce the scope of the databind,
according to what is visible, with my own Page level databind routine. So
it's not a great problem

Ok, having databinding expressions which reference non-existant data is not
a good thing...
 
Back
Top