Search:
Namespaces
Discussions
.NET v1.1
Feedback
User Control / Codebehind
Messages
Related Types
This message was discovered on
ASPFriends.com 'aspngcontrolsvb' list
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Bob Levittan (VIP)
I have a user control registered like:
<%@ Register TagPrefix="bbk" TagName="navbar" src="_navbar.ascx" %>
and then used in my HTML as:
<bbk:navbar id=Navbar2 runat="server" ForeColor="Silver" Width="100%"
BackColor="LightSteelBlue"></bbk:navbar>
So far so good. Now I want to use a property of my navbar called "brand" in
my codebehind. I have this:
Protected WithEvents navbar2 As System.Web.UI.
UserControl
in my codebehind page. How do I code using navbar2? I want to do something
like:
if navbar2.brand = "" then
but it says that "brand is not a member of System.Web.UI.
UserControl
. I know
I have to declare the control somehow to get access to it. Can someone show
me how?
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
Reply to this message...
Doug Seven
If your User Control uses code behind and is compiled in a DLL then it has
its own type (the class of the code behind).
Protected WithEvents navbar2 As MyApp.MyCustomUserControl
if navbar2.brand = "" then
If not, you need to use reflection. See:
Code Behind in Web Forms and User Controls
http://www.aspnextgen.com/tutorials.aspx?tutorialid=54
___________________________________________
Doug Seven
codejunkies.net
Are you a DotNetJunkie?
http://www.AspNextGen.com
http://www.DotNetJunkies.com
Still not enough? Buy the book:
Programming Datadriven Web Applications with ASP.NET
by Doug Seven and Don Wolthuis
http://www.amazon.com/exec/obidos/ASIN/0672321068/dotnetjunkies-20/105-60122
87-6260738
"Honestly, this really isn't a brains kind of operation"
- Benicio del Toro, The Way of the Gun
[Original message clipped]
Reply to this message...
Mike Amundsen
- add a code block to your user contorl
- add a public variable to the top of the code block (outside any
event-handler, class or method:
Public brand as String
That should do it.
MCA
-----Original Message-----
From: Bob Levittan [mailto:
Click here to reveal e-mail address
]
Sent: Wednesday, May 09, 2001 5:31 PM
To: aspngcontrolsvb
Subject: [aspngcontrolsvb] User Control / Codebehind
I have a user control registered like:
<%@ Register TagPrefix="bbk" TagName="navbar" src="_navbar.ascx" %>
and then used in my HTML as:
<bbk:navbar id=Navbar2 runat="server" ForeColor="Silver" Width="100%"
BackColor="LightSteelBlue"></bbk:navbar>
So far so good. Now I want to use a property of my navbar called "brand" in
my codebehind. I have this:
Protected WithEvents navbar2 As System.Web.UI.
UserControl
in my codebehind page. How do I code using navbar2? I want to do something
like:
if navbar2.brand = "" then
but it says that "brand is not a member of System.Web.UI.
UserControl
. I know
I have to declare the control somehow to get access to it. Can someone show
me how?
_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com
| [aspngcontrolsvb] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
Reply to this message...
Bob Levittan (VIP)
My control is not compiled. In order to do this (through VS.NET), do I have
to create a separate project with just this control and then reference the
project from my main project?
Only 5 weeks 'til June 17th.....
========================================================
If your User Control uses code behind and is compiled in a DLL then it has
its own type (the class of the code behind).
Protected WithEvents navbar2 As MyApp.MyCustomUserControl
if navbar2.brand = "" then
If not, you need to use reflection. See:
Code Behind in Web Forms and User Controls
http://www.aspnextgen.com/tutorials.aspx?tutorialid=54
___________________________________________
Doug Seven
codejunkies.net
Are you a DotNetJunkie?
http://www.AspNextGen.com
http://www.DotNetJunkies.com
Still not enough? Buy the book:
Programming Datadriven Web Applications with ASP.NET
by Doug Seven and Don Wolthuis
http://www.amazon.com/exec/obidos/ASIN/0672321068/dotnetjunkies-20/105-60122
87-6260738
"Honestly, this really isn't a brains kind of operation"
- Benicio del Toro, The Way of the Gun
[Original message clipped]
| [aspngcontrolsvb] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com
Reply to this message...
Bob Levittan (VIP)
P.S.
If I do have to create a separate project, what type of project should it
be?
===========================================
If your User Control uses code behind and is compiled in a DLL then it has
its own type (the class of the code behind).
Protected WithEvents navbar2 As MyApp.MyCustomUserControl
if navbar2.brand = "" then
If not, you need to use reflection. See:
Code Behind in Web Forms and User Controls
http://www.aspnextgen.com/tutorials.aspx?tutorialid=54
___________________________________________
Doug Seven
codejunkies.net
Are you a DotNetJunkie?
http://www.AspNextGen.com
http://www.DotNetJunkies.com
Still not enough? Buy the book:
Programming Datadriven Web Applications with ASP.NET
by Doug Seven and Don Wolthuis
http://www.amazon.com/exec/obidos/ASIN/0672321068/dotnetjunkies-20/105-60122
87-6260738
"Honestly, this really isn't a brains kind of operation"
- Benicio del Toro, The Way of the Gun
[Original message clipped]
| [aspngcontrolsvb] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com
Reply to this message...
Paul D. Murphy (VIP)
Yes and it's a Web Custom Control Project.=20
Paul
-----Original Message-----
From: Bob Levittan [mailto:
Click here to reveal e-mail address
]
Sent: Thursday, May 10, 2001 11:13 AM
To: aspngcontrolsvb
Subject: [aspngcontrolsvb] RE: User Control / Codebehind
P.S.
If I do have to create a separate project, what type of project should
it
be?
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
If your User Control uses code behind and is compiled in a DLL then it
has
its own type (the class of the code behind).
Protected WithEvents navbar2 As MyApp.MyCustomUserControl
if navbar2.brand =3D "" then
If not, you need to use reflection. See:
Code Behind in Web Forms and User Controls
http://www.aspnextgen.com/tutorials.aspx?tutorialid=3D54
___________________________________________
Doug Seven
codejunkies.net
Are you a DotNetJunkie?
http://www.AspNextGen.com
http://www.DotNetJunkies.com
Still not enough? Buy the book:
Programming Datadriven Web Applications with ASP.NET
by Doug Seven and Don Wolthuis
http://www.amazon.com/exec/obidos/ASIN/0672321068/dotnetjunkies-20/105-6
0122
87-6260738
"Honestly, this really isn't a brains kind of operation"
- Benicio del Toro, The Way of the Gun
[Original message clipped]
| [aspngcontrolsvb] member
Click here to reveal e-mail address
=3D YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
=3D JOIN/QUIT
|
http://www.asplists.com/search
=3D SEARCH Archives
_________________________________________________________________
Get your FREE download of MSN Explorer at
http://explorer.msn.com
| [aspngcontrolsvb] member
Click here to reveal e-mail address
=3D YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
=3D JOIN/QUIT
|
http://www.asplists.com/search
=3D SEARCH Archives
Reply to this message...
dave 123aspx.com (VIP)
Hi Bob,
Sorry I'm a little late here, you may have already figured this out=85
I'm assuming you want to access this
UserControl
from codebehind of the pag=
e, not codebehind of another Usercontrol
The way I do this is to place a panel control on the page, and then load th=
e usercontrol dynamically from codebehind and add it to the panel control. =
I've listed code below, but feel free to look at other examples at:
Tutorials >> UserControls
http://www.123aspx.com
/directory.asp?dir=3D10
Here is an example i use:
Option Strict On
Option Explicit On
Imports System
Imports System.Reflection
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class cbDefault : Inherits Page
Public pnlHeading as Panel
Public Sub Page_Load(Src As Object, E As EventArgs)
REM -- Load the control
Dim myUC as
UserControl
=3D LoadControl("ucHeading.ascx")
REM -- Set the Usercontrol Type
Dim ucType as Type =3D myUC.GetType()
REM -- Get access to the property
Dim ucPageHeadingProperty as
PropertyInfo
=3D ucType.GetProperty("PageHeadi=
ng")
REM -- Set the property
ucPageHeadingProperty.SetValue(myUC,"Access a Usercontrol from Code Behind"=
,Nothing)
pnlHeading.Controls.Add ( myUC )
End Sub
End Class
.
Cheers!
dave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.123aspx.com
The Largest ASP.NET Web Directory!
Find the latest ASP.NET resources --
Subscribe to our newsletter!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---------- Original Message ----------------------------------
From: "Doug Seven" <
Click here to reveal e-mail address
>
Reply-To: "aspngcontrolsvb" <
Click here to reveal e-mail address
>
Date: Wed, 9 May 2001 19:07:44 -0700
[Original message clipped]
Reply to this message...
Robert K Breton \(BOB\)
The only reason I wanted to put C# code with MY VB Code was because this
IBuySpy Module PageCounter is in C#, and I got the VB Version of the Portal
site. They are asking for a declaration in C# to be placed in my Global.asax
file, that is using VB as the language.
I bet its easier to just recode the C# declaration into VB Code than trying
to Figure out how to Link 2 CodeBehinds to 1 Global.asax using 2 seperate
languages.
void Application_Start(Object sender,
EventArgs
e)
{
Application["HitCounter"] = (long) 0;
Application["HitCounterPortalID"] = "";
Application["HitCounterLoaded"] = "";
Application["HitCounterDirtyCache"] = "false";
}
void Session_Start(Object sender,
EventArgs
e)
{
string strSessionID = Session.SessionID;
if (Application[strSessionID] == null)
{
// log a new session has started
Application[strSessionID] = strSessionID;
long l = (long) Application["HitCounter"];
l += 1;
Application["HitCounter"] = l;
// mark cache as dirty
Application["HitCounterDirtyCache"] = "true";
}
}
Theres the Code they want inside my Global.asax
I understand the VB.NET, But C#.NET Is still relatively new, and these
commands are all new to me.
Bob
Can someone convert this to VB for me, so I can see how?
----- Original Message -----
From: "dave 123aspx.com" <
Click here to reveal e-mail address
>
To: "aspngcontrolsvb" <
Click here to reveal e-mail address
>
Sent: Wednesday, May 23, 2001 9:18 AM
Subject: [aspngcontrolsvb] RE: User Control / Codebehind
Hi Bob,
Sorry I'm a little late here, you may have already figured this out.
I'm assuming you want to access this
UserControl
from codebehind of the
page, not codebehind of another Usercontrol
The way I do this is to place a panel control on the page, and then load the
usercontrol dynamically from codebehind and add it to the panel control.
I've listed code below, but feel free to look at other examples at:
Tutorials >> UserControls
http://www.123aspx.com
/directory.asp?dir=10
Here is an example i use:
Option Strict On
Option Explicit On
Imports System
Imports System.Reflection
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class cbDefault : Inherits Page
Public pnlHeading as Panel
Public Sub Page_Load(Src As Object, E As EventArgs)
REM -- Load the control
Dim myUC as
UserControl
= LoadControl("ucHeading.ascx")
REM -- Set the Usercontrol Type
Dim ucType as Type = myUC.GetType()
REM -- Get access to the property
Dim ucPageHeadingProperty as
PropertyInfo
=
ucType.GetProperty("PageHeading")
REM -- Set the property
ucPageHeadingProperty.SetValue(myUC,"Access a Usercontrol from Code
Behind",Nothing)
pnlHeading.Controls.Add ( myUC )
End Sub
End Class
.
Cheers!
dave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.123aspx.com
The Largest ASP.NET Web Directory!
Find the latest ASP.NET resources --
Subscribe to our newsletter!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---------- Original Message ----------------------------------
From: "Doug Seven" <
Click here to reveal e-mail address
>
Reply-To: "aspngcontrolsvb" <
Click here to reveal e-mail address
>
Date: Wed, 9 May 2001 19:07:44 -0700
[Original message clipped]
| [aspngcontrolsvb] member
Click here to reveal e-mail address
= YOUR ID
|
http://www.asplists.com/asplists/aspngcontrolsvb.asp
= JOIN/QUIT
|
http://www.asplists.com/search
= SEARCH Archives
Reply to this message...
System.EventArgs
System.Reflection.PropertyInfo
System.Web.UI.UserControl
System.Windows.Forms.UserControl
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com