0 out of 1 rated this helpful - Rate this topic

TemplateControl.LoadControl Method

Loads a Control.

This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list.

  Name Description
Public method LoadControl(String) Loads a Control object from a file based on a specified virtual path.
Public method LoadControl(Type, Object[]) Loads a Control object based on a specified type and constructor parameters.
Top

When you load a control into a container control, the container raises all of the added control's events until it has caught up to the current event. However, the added control does not catch up with postback data processing. For an added control to participate in postback data processing, including validation, the control must be added in the Init event rather than in the Load event.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
an idea for you....
when I create controls, I use properties to pass values into them, perhaps this could work for you....

Imports MyInstance.MyType
Imports System.Runtime.Serialization

<Serializable()> _
Public Class MyASCX_Control
    Inherits System.Web.UI.UserControl
    Implements ISerializable

   Private _myObjectParam As MyType = Nothing

    Public Property myObjectParam() As MyType
        Get
            If _myObjectParam IsNot Nothing Then
                Return _myObjectParam
            Else
                Return Nothing
            End If
        End Get
        Set(ByVal myObjectParam As MyType)
            _myObjectParam = myObjectParam
        End Set
    End Property

etc...
Passing an argument in the constructor?
Hi,

I am having some trouble with Event-Binding of a user-control
The events should be triggered in a particular instance of a class that is kept persistent between roundtrips:
<asp:Button ID="something" OnClick="MyInstance.ButtonPressed" />

Is there any way to pass in the instance of my persistent class as a value for "MyInstance" when initializing the control?

If I use LoadControl(String), I am getting an error that it is not possible to bind the event to a null-Object immediately (since MyInstance is not yet initialized).
If I use LoadControl(Type, object[]) with the CodeBehind-Type, I do not have any controls in the control loaded (of course not, since it does not have a connection to the ascx-File).
I cannot use LoadControl(Type, object[]) with the Type of the ascx-class, since it does not have a constructor that helps me.

Any suggestions, how I can solve this?
I need to initialize a control with instance directly or with anything that tells the control where to find "MyInstance". This should definitely be possible in asp, shouldn't it?

Regards and thank you for any help.
Andreas