473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Dynamically adding in User Controls

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="VB" 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="VB" 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">
Sub Page_Load(sender as Object, e as EventArgs)
if not IsPostBack

Set the Src of the control here (or maybe in the html area)

end if
</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
Jul 26 '06 #1
2 999
Hi,

Page.LoadControl can take name of the UC in and it returns you instance of
the control which you shoiuld add to the Controls collection on the Page.

Dim c As Control = Page.LoadControl("uc.ascx")
addForm.Controls.Add(c)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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="VB" 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="VB" 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">
Sub Page_Load(sender as Object, e as EventArgs)
if not IsPostBack

Set the Src of the control here (or maybe in the html area)

end if
</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

Jul 27 '06 #2
"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi,

Page.LoadControl can take name of the UC in and it returns you instance of
the control which you shoiuld add to the Controls collection on the Page.

Dim c As Control = Page.LoadControl("uc.ascx")
addForm.Controls.Add(c)
That was what I was looking for.

Thanks,

Tom
>
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"tshad" <ts**********@ftsolutions.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>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="VB" 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="VB" 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">
Sub Page_Load(sender as Object, e as EventArgs)
if not IsPostBack

Set the Src of the control here (or maybe in the html area)

end if
</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


Jul 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sameer mowade via .NET 247 | last post by:
Hello All, I have problem while dynamically removing row from the Datagrid which i have added dynamically as shown in the following code snippet. The problem is that while removing dynamically...
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
9
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
1
by: Shraddha | last post by:
Hi, I am adding some ASP.Net user controls (.ascx file) dynamically on the button click. The user control will get added as many times userhits the button. Now on the click of the submit button, I...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
1
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.