Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Jon B #1
Handle Event of Dynamically Added User Control
Hi There!
How to handle the events of a dynamically added user control?
e.g. I have following code...
Dim myUserControl as Object = LoadControl("myFirstControl.ascx")
myFirstControl fires LinkClicked event and I don't know how to handle that
LinkClicked event from containing page.
Please help!! Thanks!!!
Jon
Jon B Guest
-
Dynamically Adding User Control with Child User Control
I have a user control that has a child user control. If I drag this onto the page, it appears and functions normally. If I attempt to add the... -
Determine if custom control is being added dynamically?
Hi, Is it possible to determine in your custom control code if it is being added to the control hierarchy through page parsing or being added... -
Know in user control page_load if an user control event is going to be fired
Hi all, i have built a user control that shows a map and let the user zoom in, out, usual stuff. Putting this object in a webform the user can... -
Adding dynamically user control (ASCX) into asp.net page and handling OnClick event
Hi, I've been reading a lot's of Q&A on user controls but none seem to answer my question. Here it is. I need to add dynamically a user control,... -
onclick event for dynamically added controls?
when you build the control you will need to set it's id to a unique value. then you will need to daisy chain the click event to a handler... -
billmiami2@netscape.net #2
Re: Handle Event of Dynamically Added User Control
You will need to use addhandler to specify the event handler as in
Dim myUserControl as Object = LoadControl("myFirstControl.ascx")
AddHandler myUserControl.myEvent, AddressOf Me.MyEventHandler
Elsewhere on the page place the event handling routing you specified
Sub MyEventHandler(obj as Object, e as EventArgs)
'Do something when the event fires
End Sub
Bill E.
Hollywood, FL
Jon B wrote:that> Hi There!
>
> How to handle the events of a dynamically added user control?
>
> e.g. I have following code...
>
> Dim myUserControl as Object = LoadControl("myFirstControl.ascx")
>
> myFirstControl fires LinkClicked event and I don't know how to handle> LinkClicked event from containing page.
>
> Please help!! Thanks!!!
>
> Jonbillmiami2@netscape.net Guest
-
Jon B #3
Re: Handle Event of Dynamically Added User Control
Thanks for the reply Bill, but I get the following error message when I
tried your method...
BC30676: 'LinkClicked' is not an event of 'System.Object'.
Any ideas? Thanks again!!!
Jon
<billmiami2@netscape.net> wrote in message
news:1114770120.624232.293120@o13g2000cwo.googlegr oups.com...> You will need to use addhandler to specify the event handler as in
>
>
> Dim myUserControl as Object = LoadControl("myFirstControl.ascx")
> AddHandler myUserControl.myEvent, AddressOf Me.MyEventHandler
>
> Elsewhere on the page place the event handling routing you specified
>
> Sub MyEventHandler(obj as Object, e as EventArgs)
> 'Do something when the event fires
> End Sub
>
> Bill E.
> Hollywood, FL
>
>
>
>
> Jon B wrote:> that>> Hi There!
>>
>> How to handle the events of a dynamically added user control?
>>
>> e.g. I have following code...
>>
>> Dim myUserControl as Object = LoadControl("myFirstControl.ascx")
>>
>> myFirstControl fires LinkClicked event and I don't know how to handle>>> LinkClicked event from containing page.
>>
>> Please help!! Thanks!!!
>>
>> Jon
Jon B Guest
-
billmiami2@netscape.net #4
Re: Handle Event of Dynamically Added User Control
Well, I suppose that you need to dimension your user control not as an
object, but as an instance of the user control's type
Dim MyUserControl as usercontrolclass =
LoadControl("myFirstControl.ascx")
Bill
billmiami2@netscape.net Guest
-
Jon B #5
Re: Handle Event of Dynamically Added User Control
Thanks for the reply again Bill! But how do I dimension my user control as
the type of User control?
I'm not using Code-Behind method and my project also didn't get complied
every time I change something. Both code and HTML is in one ASCX file.
There's a ClassName attribute at the top of the page in Control directive.
But I'm unable to declare an object with that type in containing page.
So how do I go about it??
Thanks!!
Jon
<billmiami2@netscape.net> wrote in message
news:1114779666.871704.230040@o13g2000cwo.googlegr oups.com...> Well, I suppose that you need to dimension your user control not as an
> object, but as an instance of the user control's type
>
> Dim MyUserControl as usercontrolclass =
> LoadControl("myFirstControl.ascx")
>
> Bill
>
Jon B Guest
-
billmiami2@netscape.net #6
Re: Handle Event of Dynamically Added User Control
Jon,
Now I understand. Things are a bit less clear with the in-line coding.
If you don't use the ClassName attribute in your control
"myusercontrol.ascx", I think that the class is implicitly created as
ASP.myusercontrol_ascx
If you specify a class name, it will be
ASP.myspecifiedclassname
However, if you're unsure, you can load the control as an object, then
return its type with GetType as in
Dim myUserControl as Object = LoadControl("myFirstControl.ascx")
Response.Write(myUserControl.GetType.toString)
Once you know the type, you can change to
Dim myUserControl as ASP.myFirstControl =
LoadControl("myFirstControl.ascx")
AddHandler myUserControl.myCustomEvent, AddressOf Me.MyEventHandler
Bill
billmiami2@netscape.net Guest



Reply With Quote

