First of all, I hope I'd get some advice about my practice because based on the very few books I've read, they didn't write much in the aspx page..they just built some controls and used them in the aspx page, so is this approach a good practice ?
here comes my question, I thought using web controls instead of directly writing into .aspx page is better as I could reuse the code, but now I'm creating those controls and I don't think I'll reuse them again or maybe only just one more time. so do you think it's wise to create a control for the code instead of directly coding in the .aspx page ?
I was also working on a web user control for adding a new item to my db, and then I started planing for the update or edit control..I thought maybe I'd use the same control for both add and edit and start reusing my code, and on my way editing the control to be able to function as both add and edit control, I started with adding properties to the control, then a couple assignments in the Load method, then some checks with if...So I realized maybe a new control would be better!
I don't know, I'm thinking intuitively but I could really use a professional, experienced point of view.
Thanks for your time =)
Sometimes creating a user control, allows you to encapsulate some specific logic and ui elements into a separate class. Even if you are not reusing the control, the final code may be simpler to read and maintain. Take by example a Login control, if you take login related decisions in the user control and make those 'details' hidden in the rest of your code, then the code get simpler and easier to read and mantain!
If you're not going to reuse the code, then you don't want a user control or any other kind of control. Just put the appropriate code and controls onto the page.
If you find later that you do want to reuse it, then you can make a user control out of it.
If you know for sure that you are going to want to use a control (or some slight variation) then creating the user control is a no brainer.
For me, if it occurs to me that I may need similar functionality again in some future project then I will sometimes create a control just because I think it will be useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With