开发者

Should custom server control access data or be fully bound from client?

开发者 https://www.devze.com 2022-12-10 22:47 出处:网络
The question is whether it\'s better to encapsulate general data code within a server control or bind the data to the control from the client?

The question is whether it's better to encapsulate general data code within a server control or bind the data to the control from the client?

T开发者_JAVA技巧he control will be utilized by various different applications and the data is generally only for the control. So the question is, rather than duplicate the code to bind the control in every client, would it be better to let the control access the data itself?

EDIT: If the control gets data directly what would be the best way to pass an NHibernate connection?


It depends on the situation. A general rule of thumb that I follow is to use the approach that uses the least repeated code.

In your situation, it sounds like it should be in the control.

The purpose for this philosophy is easier maintenance:

If the data source changes, or the query changes, I want to change it in code as few places as possible, so if you can change it ONCE by changing the control, it's a lot easier than changing things in all of the pages that use the control.

Edit - added

Better yet would be to have the control calling a stored procedure because it's generally easier to modify a stored procedure than it is to re-deploy code that's been modified into a live environment. Of course, the code for calling the stored procedure could be in the control in your situation. Again, refer to the purpose of the philosophy.

0

精彩评论

暂无评论...
验证码 换一张
取 消