|
 |
aspx thread: Code behind and user controls
Message #1 by "Brandon Levitt" <levittbr@m...> on Wed, 6 Jun 2001 21:03:41
|
|
I've written a user control that uses a "code behind" source. The
inherited class (CriticalReportModule) was defined in a "CriticalReports"
namespace.
I now want to write code-behind source for the page that uses the user
control. In order to reference the user control (we'll say its id = Mod in
the aspx page) in the code-behind class I created an instance of the
UserControl (called "Mod") in the code-behind class...
public CriticalReports.CriticalReportModule Mod;
However whenever I do this I get "CriticalReportModule does not exist in
the class or namespace CriticalReports." Anyone know what I'm doing
wrong?
I'm using some of the dwamish7 C# for reference.
It may be easier to see what I'm trying to do if you look at the
relationship between the following:
http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
207/Modules/accountmodule_ascx.htm
http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
207/Modules/AccountModule_cs.htm
http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
207/Secure/account_aspx.htm
http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
207/Secure/Account_cs.htm
Message #2 by "Chris Scott" <chris-scott@e...> on Thu, 7 Jun 2001 08:42:46 +0100
|
|
Hi Brandon,
Have you tried inserting RUNAT="SERVER" into the control?
Best Regards,
Chris
----- Original Message -----
From: "Brandon Levitt" <levittbr@m...>
To: "ASP+" <aspx@p...>
Sent: Wednesday, June 06, 2001 9:03 PM
Subject: [aspx] Code behind and user controls
> I've written a user control that uses a "code behind" source. The
> inherited class (CriticalReportModule) was defined in a "CriticalReports"
> namespace.
> I now want to write code-behind source for the page that uses the user
> control. In order to reference the user control (we'll say its id = Mod in
> the aspx page) in the code-behind class I created an instance of the
> UserControl (called "Mod") in the code-behind class...
> public CriticalReports.CriticalReportModule Mod;
>
> However whenever I do this I get "CriticalReportModule does not exist in
> the class or namespace CriticalReports." Anyone know what I'm doing
> wrong?
>
> I'm using some of the dwamish7 C# for reference.
> It may be easier to see what I'm trying to do if you look at the
> relationship between the following:
> http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
> 207/Modules/accountmodule_ascx.htm
> http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
> 207/Modules/AccountModule_cs.htm
> http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
> 207/Secure/account_aspx.htm
> http://msdn.microsoft.com/msdn-files/026/002/071/Duwamish%
> 207/Secure/Account_cs.htm
>
>
Message #3 by "Brandon Levitt" <levittbr@m...> on Thu, 7 Jun 2001 15:16:29
|
|
Yup, runat="server" is in the tag on the aspx page.
Message #4 by "Brandon Levitt" <levittbr@m...> on Thu, 7 Jun 2001 17:37:45
|
|
I've created some example files so I can show what I'm trying to
accomplish.
//TestPageUserControl.ascx
<%@ Import Namespace="Test" %>
<%@ Control Language="c#" Inherits="Test.TestPageUC"
SRC="TestPageUserControl.cs" %>
<asp:textbox id="TB" runat="server"/>
//TestPageUserControl.cs
namespace Test{
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class TestPageUC : UserControl{
public TextBox TB;
}
}
//TestPage.aspx
<%@ Import Namespace="Test" %>
<%@ Page Language="C#" Inherits="Test.TestPageCodeBehind"
SRC="TestPage.cs"%>
<%@ Register TagPrefix="MyTags" TagName="TestPageUC"
Src="TestPageUserControl.ascx" %>
<HTML>
<HEAD>
</HEAD>
<BODY>
<form runat="server">
<MyTags:TestUC ID="UC1" runat="server"/>
</form>
</BODY>
</HTML>
//TestPage.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Test{
public class TestPageCodeBehind : Page{
public TestPageUC UC1;
void Page_Load(Object Src, EventArgs E){
UC1.TB.Text="Code Behind!";
}
}
}
While I'm at it, does anyone know the difference in placing the "using"
statements inside a namespace declaration as opposed to outside the
declaration?
|
|
 |