User control - when and why??
-
This is a basic question. When would one decide to make an user control and when would you want to add the controls to the aspx page itself? My idea was that whenever you want to add some new event to the existing control/s you would make use of the control and then add events to it. But is there any other reason why you would want to make a new control? Also if i dont need any new events, all i do is put all the controls (that normally i would put in aspx page) in a ascx page and then just add this to my page - would i get any benefit ? like in performace? Any help will be greatly appreciated ..
-
This is a basic question. When would one decide to make an user control and when would you want to add the controls to the aspx page itself? My idea was that whenever you want to add some new event to the existing control/s you would make use of the control and then add events to it. But is there any other reason why you would want to make a new control? Also if i dont need any new events, all i do is put all the controls (that normally i would put in aspx page) in a ascx page and then just add this to my page - would i get any benefit ? like in performace? Any help will be greatly appreciated ..
My biggest reason for using user controls is ...reusability. For example, I have a "Departments" dropdown list that pulls its data from a database. If I only use this on one webform, then maybe I'll just use a dropdownlist on that one form and code to populate it. But using it on many web forms, I get a benefit from creating/coding it once as its own user control, then using the user control on each of the web forms.
-
My biggest reason for using user controls is ...reusability. For example, I have a "Departments" dropdown list that pulls its data from a database. If I only use this on one webform, then maybe I'll just use a dropdownlist on that one form and code to populate it. But using it on many web forms, I get a benefit from creating/coding it once as its own user control, then using the user control on each of the web forms.
-
ummm.. makes sense. But then would i get any other benefit? I could always paste the same code without any changes.
Yes, you could always copy/paste the same code several times. On the other hand, if you ended up needing to make a minor change to that "Departments" dropdown, would you really want to have to make the change several times? Setting it up as a user control in the first place ensures that you only have to change it once.
-
Yes, you could always copy/paste the same code several times. On the other hand, if you ended up needing to make a minor change to that "Departments" dropdown, would you really want to have to make the change several times? Setting it up as a user control in the first place ensures that you only have to change it once.
ah ok. The reason I am really confused is that I have joined this new project where they insist on making controls for each and every page. None of them can be reused as they are making one ascx page for one aspx page. I just wanted to figure out if doing so is adding any advantage or is this just some kind of design that just deosnt make any sense to me :( -- modified at 17:38 Wednesday 9th August, 2006
-
ah ok. The reason I am really confused is that I have joined this new project where they insist on making controls for each and every page. None of them can be reused as they are making one ascx page for one aspx page. I just wanted to figure out if doing so is adding any advantage or is this just some kind of design that just deosnt make any sense to me :( -- modified at 17:38 Wednesday 9th August, 2006
Oh. I'm not sure why they would want to make each page a single .ascx. I don't see any advantage to that. Unless the goal was to have a single .aspx page that could dynamically swap out any of a number of .ascx's, I suppose... but otherwise, I can't think of a reason to do it that way. Have you asked your project partners? What reason do they give?
-
ah ok. The reason I am really confused is that I have joined this new project where they insist on making controls for each and every page. None of them can be reused as they are making one ascx page for one aspx page. I just wanted to figure out if doing so is adding any advantage or is this just some kind of design that just deosnt make any sense to me :( -- modified at 17:38 Wednesday 9th August, 2006
I'd say it's good practice to build controls in such a way that promotes reuse, even if the possibility of reuse hasn't yet become apparent. May as well write it in a way that's most likely to help you later. Building each page as a single control makes sense only if you're using ASP.NET 1.1 and you need multiple pages to be hosted in one URL, so they can share viewstate.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
Oh. I'm not sure why they would want to make each page a single .ascx. I don't see any advantage to that. Unless the goal was to have a single .aspx page that could dynamically swap out any of a number of .ascx's, I suppose... but otherwise, I can't think of a reason to do it that way. Have you asked your project partners? What reason do they give?
oh the guy who is the decision maker is working on .NET for the first time and i have no idea why he insists on making use of such things just because its a part of the technology or because he's new to it or because he just is complicating things :( when asked all he says is that we might use it some day. So i was wondering if you know there really is some advantage behind just creating so many user controls.
-
This is a basic question. When would one decide to make an user control and when would you want to add the controls to the aspx page itself? My idea was that whenever you want to add some new event to the existing control/s you would make use of the control and then add events to it. But is there any other reason why you would want to make a new control? Also if i dont need any new events, all i do is put all the controls (that normally i would put in aspx page) in a ascx page and then just add this to my page - would i get any benefit ? like in performace? Any help will be greatly appreciated ..
hi shilpa, I have also work on a project which is contain all user controls ecexpt on aspx web page which is load every user controls. I thinks lots of advantage like reusable is comman advantage and One of most advantages of user controls is that they can expose properties and methods like any object in the .NET Framework.