UserControl not capturing Button click event when loaded with PlaceHolder Control

R

Ralph Krausse

My UI is one table, 2 colums, one row. The cell on the left has a tree
and the cell on the right has a placeholder control. When the user
clicks on a tree item, I dynamically load the apporopiate user control
into the PlaceHolder control using this code...

objPlaceHolder.Controls.Clear();
objPlaceHolder.Controls.Add(LoadControl("nnn.ascx"));

where nnn.ascx is the appropiate control. On this user control I have
a button and hander defined but when I click on the button, the
handler NEVER gets called.

I am not sure why this happens....

Thanks
Ralph Krausse

www.consiliumsoft.com
Use the START button? Then you need CSFastRunII...
A new kind of application launcher integrated in the taskbar!
ScreenShot - http://www.consiliumsoft.com/ScreenShot.jpg
 
S

smay

When the page reloads (due to the button click) you must reload the control
in the placeholder in order for the click event in the control's codebehind
to fire. You might want to save the path "nnn.ascx" in viewstate.

Private Sub Page_Load...
If Not Page.IsPostBack Then
If Not Me.ViewState("ctrlPath") Is Nothing Then
objPlaceHolder.Controls.Add(LoadControl(Me.ViewState("ctrlPath")));
End If
End If
End Sub
 
S

smay

Just a view state variable so that you know the filename of the last control
to be loaded into the placeholder.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top