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 constructor has parameters

User Control constructor has parameters

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelpquestion
3 Posts 2 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.
  • L Offline
    L Offline
    laphijia
    wrote on last edited by
    #1

    I build a user control and added a constructor to it. The constructor takes a parameter. Now when I put the user control in a web form (drag and drop) I don't know where to set the parameter. What happens is that I get this error: Compiler Error Message: CS1501: No overload for method 'ItemFields' takes '0' arguments Source Error: Line 31: private static bool __initialized = false; Line 32: Line 33: public ItemFields_ascx() { Line 34: if ((ASP.ItemFields_ascx.__initialized == false)) { Line 35: ASP.ItemFields_ascx.__initialized = true; Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\AspProjectOne\2eab3c48\dc018b2c\onc_fead.0.cs Line: 33 Thing is I don't know WHERE to initialize the control with the parameter for the constructor. I was wondering if in the ASPX page is the right place: orHere??? Edd

    N 1 Reply Last reply
    0
    • L laphijia

      I build a user control and added a constructor to it. The constructor takes a parameter. Now when I put the user control in a web form (drag and drop) I don't know where to set the parameter. What happens is that I get this error: Compiler Error Message: CS1501: No overload for method 'ItemFields' takes '0' arguments Source Error: Line 31: private static bool __initialized = false; Line 32: Line 33: public ItemFields_ascx() { Line 34: if ((ASP.ItemFields_ascx.__initialized == false)) { Line 35: ASP.ItemFields_ascx.__initialized = true; Source File: c:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\AspProjectOne\2eab3c48\dc018b2c\onc_fead.0.cs Line: 33 Thing is I don't know WHERE to initialize the control with the parameter for the constructor. I was wondering if in the ASPX page is the right place: orHere??? Edd

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Look at the code behind. You should see it being instantiated using the default constructor.

      L 1 Reply Last reply
      0
      • N Not Active

        Look at the code behind. You should see it being instantiated using the default constructor.

        L Offline
        L Offline
        laphijia
        wrote on last edited by
        #3

        I found out on MSDN that when drag dropping a control Visual Studio doesn't automatically create the declaration in the Code behind file. In fact if our control is called UserControl1 and is has a public property called StringProperty we cannot access it by default by calling UserControl1.StringProperty = "hello"; On MSDN they say to add protected UserControl UserControl1; Done this and accessing the control works. Anyway I still haven initialized my constructor. If I modify my declaration to protected UserControl UserControl1 = new UserControl(ab1, ab2, ab3....) I still receive the error no overloaded method for UserControl takes 0 parameters. I used a workaround of declaring a property and assigning it to the value I want on the Page_Load in my case works but there must be a proper way to do this. Edd

        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