CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: help

  1. #1
    Join Date
    Apr 2002
    Posts
    17

    help

    Please, help me !
    I dinamicllly load my web user control (.ascx) in my .aspx page ,
    but .asxc file containss a control textbox and the error is that the
    textbox control must be in "form runat=server", but i want my
    "form runat=server" to be in .aspx file.

  2. #2
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    173

    Lightbulb

    You are correct, there should not be a "form runat=server" tag in your .ascx file.

    After a little experimentation I would guess you are using
    Code:
    Me.Controls.Add(LoadControl("MyControl.ascx"))
    or something similar. Instead, add the following line to the top of your script page:
    Code:
    Protected MyForm As System.Web.UI.HtmlControls.HtmlForm
    where "MyForm" is the ID of the form on you aspx page. Then, the following should work:
    Code:
    MyForm.Controls.Add(LoadControl("MyControl.ascx"))
    As an alternative, you could add your control dynamically to some other control inside the form, such as a panel or table.

    BTW, I just looked at the MSDN web site and in their documentation they say to use Page.Controls.Add(...) which, in fact, does not work. Go figure.
    Hope this helps!

    pjp
    Last edited by pjpark; June 5th, 2002 at 04:18 PM.
    Preston Park
    CTT+, MCT, MCSD
    http://www.prestonpark.com/

  3. #3
    Join Date
    Apr 2000
    Location
    Dallas, TX
    Posts
    173

    Exclamation Update

    The MS documentation has an example with the line
    Code:
    Page.Controls.Add(C1)
    This is technically correct but practically useless (sort of like the balloon/helicopter jokes) since the new control will be added at the end of the page after the closing form tag.

    The accepted way to add user web controls at run time is to add them to an existing container control on the page such as a panel or table cell.

    However, my code in the previous post will work as well if you just want throw your new controls in at the end of your web form.

    HTH,

    pjp
    Preston Park
    CTT+, MCT, MCSD
    http://www.prestonpark.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured