Ask a Question related to ASP.NET General, Design and Development.
-
Marc Hoeppner #1
Re: User Controls and CodeBehind
Hi,
It may sound stupid, but this happens when you forget to compile the .cs
files first. If this is not the problem and the compile went ok, then you'd
have to check all the namespaces and files again, but I am sure you did that
already. Do you use VS.NET?
Best regards,
Marc Höppner
NeoGeo
"Dave" <lyd@cambridgemedia.com.au.nospam> wrote in message
news:eh9Ra.451$FZ6.6743@nnrp1.ozemail.com.au...recognised> Hi,
> I'm having trouble trying to get a UserControl (ascx page) to bein> in the codebehind of an aspx.cs page. From what I've been reading in this
> newsgroup, all I have to do is register my ascx page in my aspx page thenreferenced> my aspx.cs page add a reference to the control's ID like so:
>
> index.aspx:
> ------------------------------------------------------------------------
> <%@ Page Language="C#" Src="index.aspx.cs" Inherits="Site.Home" %>
> <%@ Register TagPrefix="Menu" TagName="MyMenu" Src="menu.ascx" %>
> ..
> ..
> <Menu:MyMenu id="ctlControl" runat="server">
>
>
> index.aspx.cs
> ------------------------------------------------------------------------
> namespace Site
> {
> public class Home : System.Web.UI.Page
> {
> protected Site.Controls.Menu ctlControl;
> ....
> }
> }
>
>
>
> menu.ascx
> ------------------------------------------------------------------------
> <%@ Control Language="C#" Inherits="Site.Controls.Menu" Src="menu.ascx.cs"
> %>
> ..
> ..
>
>
>
> menu.ascx.cs
> ------------------------------------------------------------------------
> namespace Site.Controls
> {
> public class Menu : System.Web.UI.UserControl
> {
> ....
> }
> }
>
>
>
> However, I keep getting an error message specifying that the class or
> namespace does not exist. I have tried everything from changing the
> namespace and class names but I cannot get the usercontrol to beblock> in the codebehind page. When I reference the user control in a script> inside the aspx page, it works fine. Does anyone know what I'm doing wrong
> or how to fix this?
>
> Thanks
> Dave
>
>
Marc Hoeppner Guest
-
Why the properties of web user controls which inherted from my custom base UI controls MISSED?
Why the properties of web user controls which inherted from my custom base UI controls MISSED? How should I to set enable? -
using javascript in User controls to access server controls of the user control
Hello all, I have an asp.net textbox (named txtHidden) and an HtmlButton(named btnAction). I wanted to write a javascript function which will get... -
user controls: dynamiclly added child controls dont survive post back ?
hi, i have some strange behaviour: i've created a web user control that add's some child controls (e.g: textbox, image buttons) to its control... -
automatic insertion of controls on codebehind
I create a new webform (I always use codebehind), and I insert some server-side controls into the form (the ASPX) Later, I switch to codeview, and... -
Refrencing user controls in codebehind
Hi Rory, You will need to call LoadControl everytime no matter which value IsPostBack is set to. From your post it seems like you're calling it... -
Dave #2
Re: User Controls and CodeBehind
Hmmmm.. that sounds strange. I thought the pages are compiled when they are
first loaded. The funny thing is that when I reference the control in the
script block of the aspx page it works fine and if I load the control in the
aspx page by the just it's tag name without referencing it that also works
fine. But why can't I reference the control in the codebehind of an aspx
page? I need to be able to reference the control as I need to access some
properties inside the control. Btw, I'm not using VS.NET.
Thanks
Dave
"Marc Hoeppner" <marchoeppner@hotmail.com> wrote in message
news:#lkCvG4SDHA.1552@TK2MSFTNGP12.phx.gbl...you'd> Hi,
>
> It may sound stupid, but this happens when you forget to compile the .cs
> files first. If this is not the problem and the compile went ok, thenthat> have to check all the namespaces and files again, but I am sure you didthis> already. Do you use VS.NET?
>
> Best regards,
>
> Marc Höppner
> NeoGeo
>
> "Dave" <lyd@cambridgemedia.com.au.nospam> wrote in message
> news:eh9Ra.451$FZ6.6743@nnrp1.ozemail.com.au...> recognised> > Hi,
> > I'm having trouble trying to get a UserControl (ascx page) to be> > in the codebehind of an aspx.cs page. From what I've been reading inthen> > newsgroup, all I have to do is register my ascx page in my aspx pageSrc="menu.ascx.cs"> in> > my aspx.cs page add a reference to the control's ID like so:
> >
> > index.aspx:
> > ------------------------------------------------------------------------
> > <%@ Page Language="C#" Src="index.aspx.cs" Inherits="Site.Home" %>
> > <%@ Register TagPrefix="Menu" TagName="MyMenu" Src="menu.ascx" %>
> > ..
> > ..
> > <Menu:MyMenu id="ctlControl" runat="server">
> >
> >
> > index.aspx.cs
> > ------------------------------------------------------------------------
> > namespace Site
> > {
> > public class Home : System.Web.UI.Page
> > {
> > protected Site.Controls.Menu ctlControl;
> > ....
> > }
> > }
> >
> >
> >
> > menu.ascx
> > ------------------------------------------------------------------------
> > <%@ Control Language="C#" Inherits="Site.Controls.Menu"wrong> referenced> > %>
> > ..
> > ..
> >
> >
> >
> > menu.ascx.cs
> > ------------------------------------------------------------------------
> > namespace Site.Controls
> > {
> > public class Menu : System.Web.UI.UserControl
> > {
> > ....
> > }
> > }
> >
> >
> >
> > However, I keep getting an error message specifying that the class or
> > namespace does not exist. I have tried everything from changing the
> > namespace and class names but I cannot get the usercontrol to be> block> > in the codebehind page. When I reference the user control in a script> > inside the aspx page, it works fine. Does anyone know what I'm doing>> > or how to fix this?
> >
> > Thanks
> > Dave
> >
> >
>
Dave Guest



Reply With Quote

