User control loosing its contents when loaded programatically
- by Phil
I have a usercontrol which contains 2 repeaters and the code to populate them with data. If i manually insert this into the page then it works correctly, the repeaters populate etc.
If I load it programatically using this method;
1) add class name to user control
ClassName="ContentModule"
2) reference this in the default.aspx
<%@ Reference Control="~/modules/content.ascx" %>
3) Add the code to my codebehind page_load to do the loading;
Private loadmodule As ASP.ContentModule
Try
If themodule = "content" Then
loadmodule = CType(LoadControl("~\Modules\Content.ascx"), ASP.ContentModule)
Modulecontainer.Controls.Add(loadmodule)
End If
Catch ex As Exception
Response.Write(ex.ToString & "<br />")
End Try
Nothing from within the usercontrol is loaded to the page. Although if I add some static text i.e "TEST" to the top of the usercontrol this is displayed ok on the default.aspx page. This makes me think that the control is loaded ok, but there is something in the way I have loaded it that is causing the contents to not properly execute.
Very frustrating this one! Any help greatly appreciated!