Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Dynamically adding in User Controls

 
Thread Tools Search this Thread
Old 07-26-2006, 10:42 PM   #1
Default 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




tshad
  Reply With Quote
Old 07-27-2006, 11:35 AM   #2
Teemu Keiski
 
Posts: n/a
Default Re: Dynamically adding in User Controls
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" <> wrote in message
news:%...
> 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
>





Teemu Keiski
  Reply With Quote
Old 07-27-2006, 07:19 PM   #3
tshad
 
Posts: n/a
Default Re: Dynamically adding in User Controls
"Teemu Keiski" <> wrote in message
news:%...
> 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" <> wrote in message
> news:%...
>> 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
>>

>
>





tshad
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with the adding jars dynamically kmurthy7 General Help Related Topics 0 02-19-2009 08:40 PM
ASP.NET with User Interface Process Application Block robinp Software 0 03-05-2007 10:01 AM
Dynamically adding WebUserControl in aspx page sureshsekaran Software 2 10-18-2006 08:20 AM
How i can populate all fileds dynamically in jsp using javascript? vijendra Software 1 10-06-2006 01:33 PM
Any DVD Player that can override User Prohibitions? Walter Traprock DVD Video 3 12-03-2005 11:43 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46