User Controls

Discussion in 'ASP .Net' started by Michael, Nov 8, 2003.

  1. Michael

    Michael Guest

    Thank you for any help you can provide.

    This is what I have:
    index.aspx - contains nothing but a form with runat = server
    header.ascx - contains asp image box
    welcome.ascx - contains text
    footer.ascx - contains text
    login.ascx - contains asp/web labels and text boxes.

    The index page is simply a container for all the user controls. The
    header, footer, and welcome controls are always included. The login
    control should only be included if the user has not logged in.

    Everything runs perfectly if the login control in not included. When
    the login control is included I get an error saying that the control
    _ctl1_txtUser must reside between the form tags with runat set to
    server. The actual control name is txtUser. I understand why the
    name changes. What I don't understand is why it has to be in the form
    tag. While investigating, I have read in other threads that controls
    on user controls are rendered between the form tags of the parent
    object. Can anyone offer any suggestions?
    Michael, Nov 8, 2003
    #1
    1. Advertising

  2. Michael

    Jos Guest

    Michael wrote:
    > Thank you for any help you can provide.
    >
    > This is what I have:
    > index.aspx - contains nothing but a form with runat = server
    > header.ascx - contains asp image box
    > welcome.ascx - contains text
    > footer.ascx - contains text
    > login.ascx - contains asp/web labels and text boxes.
    >
    > The index page is simply a container for all the user controls. The
    > header, footer, and welcome controls are always included. The login
    > control should only be included if the user has not logged in.
    >
    > Everything runs perfectly if the login control in not included. When
    > the login control is included I get an error saying that the control
    > _ctl1_txtUser must reside between the form tags with runat set to
    > server. The actual control name is txtUser. I understand why the
    > name changes. What I don't understand is why it has to be in the form
    > tag. While investigating, I have read in other threads that controls
    > on user controls are rendered between the form tags of the parent
    > object. Can anyone offer any suggestions?


    Just move the <form runat="server"> and </form> tags in the body
    of your index.aspx file, in such a way that the login user control
    is included.

    --

    Jos
    Jos, Nov 8, 2003
    #2
    1. Advertising

  3. Michael

    Keith Guest

    Michael,

    I am assuming you are using the dynamic loading of the
    form. This is where you add controls from the code. If
    not completely ignore this post because it will confuse
    you and go with the suggestion of Jos.

    You should put a panel inside the <form></form> and add
    all of your components to it. That way you can assure
    that your components are added in the correct location.

    Another suggestion (not sure if this one will work, but I
    am assuming it will) would be to name your form tag and
    add your items to the form tag. This again will assure
    that you have you items added inside your form tags.

    Something else to consider, You don't have to load these
    controls dynamically. You can actually set their
    visibility to true or false depending on if you would
    like to display them.

    I have no proof of this, but I think the dynamic loading
    will be quicker because you are not loading all of the
    objects every time you load the page. You are only
    loading those that you specify based on if the user is
    logged in or not.

    There is a great example of this in the IBuySpy portal at
    http://www.asp.net/Default.aspx?tabindex=5&tabid=42.
    This has also evolved into http://dotnetnuke.com

    Keith

    >-----Original Message-----
    >Thank you for any help you can provide.
    >
    >This is what I have:
    >index.aspx - contains nothing but a form with runat =

    server
    >header.ascx - contains asp image box
    >welcome.ascx - contains text
    >footer.ascx - contains text
    >login.ascx - contains asp/web labels and text boxes.
    >
    >The index page is simply a container for all the user

    controls. The
    >header, footer, and welcome controls are always

    included. The login
    >control should only be included if the user has not

    logged in.
    >
    >Everything runs perfectly if the login control in not

    included. When
    >the login control is included I get an error saying that

    the control
    >_ctl1_txtUser must reside between the form tags with

    runat set to
    >server. The actual control name is txtUser. I

    understand why the
    >name changes. What I don't understand is why it has to

    be in the form
    >tag. While investigating, I have read in other threads

    that controls
    >on user controls are rendered between the form tags of

    the parent
    >object. Can anyone offer any suggestions?
    >.
    >
    Keith, Nov 8, 2003
    #3
  4. Michael,

    If you want to dynamically load the control to the page use a placeholder
    control. The placeholder control simply shows where a dynamically loaded
    control will appear on the page.

    My website, www.aboutfortunate.com, uses a single page for the entire site
    and switches it's content by dynamically loading various user controls into
    a single placeholder.

    If you'd like example code for doing so it's located in the site's code
    library. Just click on the code library and then use the search box there to
    search for: "dynamically load user control" or something similar and you'll
    find the example.

    Sincerely,

    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzche


    "Michael" <> wrote in message
    news:...
    > Thank you for any help you can provide.
    >
    > This is what I have:
    > index.aspx - contains nothing but a form with runat = server
    > header.ascx - contains asp image box
    > welcome.ascx - contains text
    > footer.ascx - contains text
    > login.ascx - contains asp/web labels and text boxes.
    >
    > The index page is simply a container for all the user controls. The
    > header, footer, and welcome controls are always included. The login
    > control should only be included if the user has not logged in.
    >
    > Everything runs perfectly if the login control in not included. When
    > the login control is included I get an error saying that the control
    > _ctl1_txtUser must reside between the form tags with runat set to
    > server. The actual control name is txtUser. I understand why the
    > name changes. What I don't understand is why it has to be in the form
    > tag. While investigating, I have read in other threads that controls
    > on user controls are rendered between the form tags of the parent
    > object. Can anyone offer any suggestions?
    S. Justin Gengo, Nov 8, 2003
    #4
  5. Michael

    Michael Guest

    Thank you everyone for your suggestions.

    Justin,

    This is exactly what I was looking for. I have and index page and the
    content (user control) will change with the users selections.

    Thank you,
    Michael


    "S. Justin Gengo" <> wrote in message news:<#>...
    > Michael,
    >
    > If you want to dynamically load the control to the page use a placeholder
    > control. The placeholder control simply shows where a dynamically loaded
    > control will appear on the page.
    >
    > My website, www.aboutfortunate.com, uses a single page for the entire site
    > and switches it's content by dynamically loading various user controls into
    > a single placeholder.
    >
    > If you'd like example code for doing so it's located in the site's code
    > library. Just click on the code library and then use the search box there to
    > search for: "dynamically load user control" or something similar and you'll
    > find the example.
    >
    > Sincerely,
    >
    > --
    > S. Justin Gengo, MCP
    > Web Developer
    >
    > Free code library at:
    > www.aboutfortunate.com
    >
    > "Out of chaos comes order."
    > Nietzche
    >
    >
    > "Michael" <> wrote in message
    > news:...
    > > Thank you for any help you can provide.
    > >
    > > This is what I have:
    > > index.aspx - contains nothing but a form with runat = server
    > > header.ascx - contains asp image box
    > > welcome.ascx - contains text
    > > footer.ascx - contains text
    > > login.ascx - contains asp/web labels and text boxes.
    > >
    > > The index page is simply a container for all the user controls. The
    > > header, footer, and welcome controls are always included. The login
    > > control should only be included if the user has not logged in.
    > >
    > > Everything runs perfectly if the login control in not included. When
    > > the login control is included I get an error saying that the control
    > > _ctl1_txtUser must reside between the form tags with runat set to
    > > server. The actual control name is txtUser. I understand why the
    > > name changes. What I don't understand is why it has to be in the form
    > > tag. While investigating, I have read in other threads that controls
    > > on user controls are rendered between the form tags of the parent
    > > object. Can anyone offer any suggestions?
    Michael, Nov 8, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. trinitypete

    HTML Controls and User controls

    trinitypete, Jun 25, 2003, in forum: ASP .Net
    Replies:
    6
    Views:
    3,352
    trinitypete
    Jun 26, 2003
  2. Axel Dahmen
    Replies:
    1
    Views:
    470
    Teemu Keiski
    Nov 12, 2003
  3. Nathan Sokalski
    Replies:
    4
    Views:
    1,131
    Muhammad Naveed Yaseen
    Sep 5, 2007
  4. Faizan Ahmed
    Replies:
    1
    Views:
    270
    John Saunders
    Jan 4, 2005
  5. Faizan Ahmed
    Replies:
    1
    Views:
    345
    John Saunders
    Jan 4, 2005
Loading...

Share This Page