Re: Dynamically adding in User Controls
- From: "tshad" <tscheiderich@xxxxxxxxxxxxxxx>
- Date: Thu, 27 Jul 2006 18:06:06 -0700
That's what I was looking for.
This would allow me to load or not load depending on values in my session
variables.
Thanks,
Tom
"Dave Sexton" <dave@jwa[remove.this]online.com> wrote in message
news:eRHcB6TsGHA.3480@xxxxxxxxxxxxxxxxxxxxxxx
Hi Tom,
You could load the appropriate UserControl into a PlaceHolder in a
Page.Init event handler:
<!-- declare the placeholder -->
<asp:PlaceHolder runat="server" id="headerPlaceHolder" />
<script runat="server">
void Page_Init(object sender, EventArgs e)
{
// Even on post backs the following code must be executed to ensure
that the UserControl is part of the
// page hierarchy of controls
// create the virtual path to the UserControl using data from the
current Session
string headerControlPath = "~/SegmentsByCompany/" +
Session["CompanyName"] + "_Header.ascx";
// load the appropriate UserControl
Control headerControl = Page.LoadControl(headerControlPath);
// add the UserControl to the PlaceHolder
headerPlaceHolder.Controls.Add(headerControl);
}
</script>
--
Dave Sexton
"tshad" <tscheiderich@xxxxxxxxxxxxxxx> wrote in message
news:e3x7oCQsGHA.4596@xxxxxxxxxxxxxxxxxxxxxxx
Is there a way to dynamically add in User Controls where I would get the
name from a session variable:
If I have the following code:
******************************************************************************
<%@ Page Language="C#" trace="false" debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Register TagPrefix="fts" TagName="Navigate" Src="sdhcNavigate.ascx"
%>
<%@ Register TagPrefix="fts" TagName="Navigate" Src="ft2Navigate.ascx" %>
<%@ Register TagPrefix="fts" TagName="Navigate" Src="sbNavigate.ascx" %>
<html>
<head>
<title>:: Staffing Workshop ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body id="myBody" runat="server">
<form id="addForm" runat="server">
<fts:Navigate runat="Server"/>
</form>
</body>
</html>
********************************************************************************
I would like to change it so that I can do something like changing the
Src attribute of the Register statement based on a session variable.
For example if my session variable "company" was either
"sdhcNavigate.ascx", "ft2Navigate.ascx" or "sbNavigate.ascx"
******************************************************************************
<%@ Page Language="C#" trace="false" debug="true" ContentType="text/html"
ResponseEncoding="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ Register TagPrefix="fts" TagName="Navigate" Src="" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
Set the Src of the control here (or maybe in the html area)
}
</script
<html>
<head>
<title>:: Staffing Workshop ::</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<body id="myBody" runat="server">
<form id="addForm" runat="server">
<fts:Navigate runat="Server"/>
</form>
</body>
</html>
********************************************************************************
I would use this in all my 50 pages to load the control based on the
company.
Thanks,
Tom
.
- Prev by Date: Re: String read only error
- Next by Date: Web apps x 2 - Sharing session
- Previous by thread: check file size before upload
- Next by thread: Web apps x 2 - Sharing session
- Index(es):
Relevant Pages
|