2

I've been playing around with assigning an ASP.NET WebControl's DataSource when I'm handling its DataBinding event. For general data binding logic in my pages, it seems to work well in organizing things.

What arguments are there for not doing this?

1 Answer 1

2

Just off the top of my head, I would argue against doing this for two reasons:

1) The design smells 2) It obscures what's really happening

For #1, I say this because in order to handle its databinding event, it has to have begun binding to something already. To change what it's binding to in mid-stream isn't what I would call an ideal design.

This leads to #2, in that if someone creates one of your controls, and calls .DataBind() on it, and it internally starts binding to something else, it's entirely unclear to the caller what's going on.

While I haven't looked at it from a technical perspective, it seems to me that you'd be raising the possibility of a recursive databinding infinite loop as well. I guess I'd really need to see some code to tell if what you were doing was acceptable, or if there were better ways of doing it.

1
  • I see what you mean by #1. For #2... I'm not doing this for my UserControls, but for the regular ASP.NET WebControls I have on my pages. For my UserControls, I would create a new event "NeedDataSource" (like the Telerik controls have) that would raise if the DataSource is null when DataBind is called.
    – Chris
    Apr 29, 2009 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.