Loading user controls programatically into a placeholder (asp.net)
Posted
by Phil
on Stack Overflow
See other posts from Stack Overflow
or by Phil
Published on 2010-04-15T09:51:57Z
Indexed on
2010/04/15
10:43 UTC
Read the original article
Hit count: 192
In my .aspx page I have;
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" AspCompat="True" %>
<%@ Register src="Modules/Content.ascx" tagname="Content" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="Modulecontainer" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
In my aspx.vb I have;
Try
Dim loadmodule As UserControl
loadmodule = Me.LoadControl("~/modules/content.ascx")
Modulecontainer.Controls.Add(loadmodule)
Catch ex As Exception
Response.Write(ex.ToString & "<br />")
End Try
The result is an empty placeholder and no errors.
Thanks a lot for any assistance
P.S after Fat_Tony's answer I changed the code to;
Try
Dim loadmodule As ASP.ContentModule
loadmodule = CType(LoadControl("~\Modules\Content.ascx"), ASP.ContentModule)
Modulecontainer.Controls.Add(loadmodule)
Catch ex As Exception
Response.Write(ex.ToString & "<br />")
End Try
But still no results unfortunately.
© Stack Overflow or respective owner