Results 1 to 3 of 3

Thread: ASCX and Tag Params

  1. #1

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497

    ASCX and Tag Params

    I have created some custom forms (ascx files) and am trying to programmatically load some at run-time.

    I can load them with the following code:

    VB Code:
    1. Dim WC1 As TempControl = LoadControl("template.ascx")
    2. WC1.EnableViewState = True
    3. 'WC1.myVar = "hi"
    4. pnlWorkspace.Controls.Add(WC1)

    Notice the commented line.

    In the ascx file, there is a variable, myVar. I would like to set a value for it. If the tag were created at design time, it would look like this:

    Code:
    <rat:template myVar="hi" id="temp1" runat="server" />
    How do I do the commented line?
    Last edited by Lord_Rat; Dec 16th, 2002 at 01:03 PM.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  2. #2
    Member HumanCompiler's Avatar
    Join Date
    Dec 2002
    Location
    Decatur, IN USA
    Posts
    52
    the commented out line should work. make sure it's access is public (wherever in your ascx it's declared)
    -Erik Porter
    .NET MVP

  3. #3

    Thread Starter
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    It is and it still doesn't.

    If you have Visual Studio, once the item is created, the UserControl object does not have the methods or properties of the Tag that were created for that tag in specific.

    EG If I create a Public Variable within the tag called myVar, I can put that in the tag ass myVar="something", but I cannot in the code behind do WC1.myVar = "something" since "myVar" is not a valid UserControl property. I have also tried creating a class definition that inherits user control and specifies the public items, but then I get an invalid cast exception when I try to load object with the derived class.
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

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