stop databind for invisible controls?

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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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,
 
M

Martin

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
 
E

Eliyahu Goldin

... 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
 
J

John Saunders

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?
 
M

Martin

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
 
J

John Saunders

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top