Re: 'Context' is not a member of....
- From: rn5a@xxxxxxxxxxxxxx
- Date: 24 Nov 2006 10:42:43 -0800
Karl, assuming that the code behind of the user control i.e
Enter.ascx.vb resides in the App_Code directory, if I add the CodeFile
attribute to the @Control directive like this:
<%@ Control Language="VB" CodeFile="App_Code\Enter.ascx.vb"
Inherits="Details.EnterCB" %>
the following error gets generated:
The file '/aspx/App_Code/Enter.ascx.vb' is in the special directory
'App_Code', which is not allowed.
If the code behind of the user control Enter.ascx.vb is placed in some
directory other than the App_Code, then when I try to use this user
control in the code behind of an ASPX page by importing the namespace &
using the class name as the type
Imports Details
Public Class MyClass : Inherits Page
Public Enter1 As EnterCB
........
........
End Class
then I get the following error:
Type 'EnterCB' is not defined.
pointing to the line which declares the variable 'Enter1'.
I also compiled Enter.ascx.vb into a DLL in the bin directory
(Enter.ascx.vb not residing in the App_Code directory) & used the
CodeFile attribute in the @Control directive in the ascx file but this
generates the following error:
Make sure that the class defined in this code file matches the
'inherits' attribute, and that it extends the correct base class (e.g.
Page or UserControl).
which points to the
Imports System
line in Enter.ascx.vb. I have ensured both the conditions outlined in
the error message but I don't understand why the error persists.
It's better I adhere to the DLL in the bin directory without using the
CodeFile attribute in the @Control directive. The more I delve into
this, the more I am getting confused....
Karl Seguin wrote:
Actually, I'm about 90% sure that I'm right...did you give it a try? it's a
pretty simple fix to try and solve your problem...
The problem is that the ascx file expects to have access to the Context
variable which is accessible as part of the UserControl class...
because you don't have a CodeFile, your ASCX file doesn't have any
codebehind associated with it...so there's no context...
It works when you drop a dll into the bin folder because the Inherits kicks
in and now there IS a codebehind file for your class which does inherit from
UserControl so there IS a Context variable...
You're mixing CodeFile and Inherits...
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1164379759.061131.104060@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Karl, I don't think that the absence of CodeFile is the cause of the
problem. You have replied to my post titled "App_Code & bin". VWD
behaves erratically in this case precisely because of the same reason
i.e. if I relocate the code behind Enter.ascx.vb to some directory
other than the App_Code directory & then compile Enter.ascx.vb into a
DLL in the bin directory using VBC, then VWD no longer displays the
'Context' is not a member of 'ASP.enter_ascx'
error when the mouse is moved over the line
<%@ Control Language="VB" Inherits="Details.EnterCB" %>
in VWD but if I just have the code behind Enter.ascx.vb in the App_Code
directory (& no DLL in the bin directory), then VWD shows the above
error when the mouse is hovered over the above line.
BTW, could you please explain me what does "Context" mean here?
Karl Seguin wrote:
I could be wrong, but shouldn't your @Control directive have a CodeFile
attribute which points to the .vb file?
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
<rn5a@xxxxxxxxxxxxxx> wrote in message
news:1164368483.620226.35810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a user control named Enter.ascx which has 2 TextBoxes. The 2
TextBoxes are named txt1 & txt2. The entire logic of this user control
(like the properties of the 2 TextBoxes using set/get etc.) is
encapsulated in a code behind page named Enter.ascx.vb. The code-behind
also creates TextChanged events for the 2 TextBoxes. This is the code
in Enter.ascx.vb:
Namespace Details
Public Class EnterCB : Inherits UserControl
Public WithEvents txt1 As TextBox
Public WithEvents txt2 As TextBox
'creating a few Properties for the
'2 TextBoxes using Set/Get
'create events for the 2 TextBoxes
Public Event TextChangedEvent(ByVal obj As Object, ByVal ea As
EventArgs)
Protected Sub txt1Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt1.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
Protected Sub txt2Changed(ByVal obj As Object, ByVal ea As
EventArgs) Handles txt2.TextChanged
RaiseEvent TextChangedEvent(obj, ea)
End Sub
End Class
End Namespace
This is how I am encompassing the above code behind in Enter.ascx:
<%@ Control Language="VB" Inherits="Details.EnterCB" %>
<asp:TextBox ID="txt1" runat="server"><br>
<asp:TextBox ID="txt2" runat="server">
As such the above user control when registered in an ASPX page works
fine & even the Events associated with the 2 TextBoxes in the user
control fire in the ASPX page when the text in the TextBoxes change.
But Visual Web Developer 2005 Express Edition (which is what I use for
creating & editing ASP.NET apps) throws the following error
'Context' is not a member of 'ASP.enter_ascx'.
when the mouse is moved over the
<%@ Control Language="VB" Inherits="Details.EnterCB" %>
line in Enter.ascx. Now first of all, what does this error mean? What
is 'Context' here? & secondly, why is VWD generating this error?
.
- Follow-Ups:
- Re: 'Context' is not a member of....
- From: Karl Seguin
- Re: 'Context' is not a member of....
- References:
- 'Context' is not a member of....
- From: rn5a
- Re: 'Context' is not a member of....
- From: Karl Seguin
- Re: 'Context' is not a member of....
- From: rn5a
- Re: 'Context' is not a member of....
- From: Karl Seguin
- 'Context' is not a member of....
- Prev by Date: Re: HTML POST
- Next by Date: Re: A good book...
- Previous by thread: Re: 'Context' is not a member of....
- Next by thread: Re: 'Context' is not a member of....
- Index(es):
Relevant Pages
|