473,395 Members | 1,975 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,395 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 1167
Hi,

The way I do this:

Don't put any register tag prefixes.
Put a placeholder where you want the control to appear.
In your code behind load the control you want, i.e.:

Dim MyControl As New Control
MyControl = LoadControl("TravelClinicSearch.ascx")
plcDatabases.Controls.Add(MyControl)

Where plcDatabases is the name of the placeholder. Obviously, the
control name can be a variable.

Hope this helps.

Gareth

tshad wrote:
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
That was what I was looking for.

I wanted to be able to load a control depending on settings in my session
variables and this would allow me to do that.

Thanks,

Tom
"gareth" <ga****************@gmail.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hi,

The way I do this:

Don't put any register tag prefixes.
Put a placeholder where you want the control to appear.
In your code behind load the control you want, i.e.:

Dim MyControl As New Control
MyControl = LoadControl("TravelClinicSearch.ascx")
plcDatabases.Controls.Add(MyControl)

Where plcDatabases is the name of the placeholder. Obviously, the
control name can be a variable.

Hope this helps.

Gareth

tshad wrote:
>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 28 '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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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.