Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. User control - when and why??

User control - when and why??

Scheduled Pinned Locked Moved ASP.NET
questionhelp
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shilpa1
    wrote on last edited by
    #1

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

    M H 2 Replies Last reply
    0
    • S Shilpa1

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

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • M Mike Ellison

        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.

        S Offline
        S Offline
        Shilpa1
        wrote on last edited by
        #3

        ummm.. makes sense. But then would i get any other benefit? I could always paste the same code without any changes.

        M 1 Reply Last reply
        0
        • S Shilpa1

          ummm.. makes sense. But then would i get any other benefit? I could always paste the same code without any changes.

          M Offline
          M Offline
          Mike Ellison
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • M Mike Ellison

            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.

            S Offline
            S Offline
            Shilpa1
            wrote on last edited by
            #5

            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

            M C 2 Replies Last reply
            0
            • S Shilpa1

              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

              M Offline
              M Offline
              Mike Ellison
              wrote on last edited by
              #6

              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?

              S 1 Reply Last reply
              0
              • S Shilpa1

                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

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • M Mike Ellison

                  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?

                  S Offline
                  S Offline
                  Shilpa1
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0
                  • S Shilpa1

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

                    H Offline
                    H Offline
                    hi_arv
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups