473,725 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using User Control from class library

Hi,

I am trying to create a User Control that is located in a seperate class
library. The User Control contains a textbox and a button.
The page generates an exception when it tries to access the code variable
that are supposed to be linked to the contained controls.

It runs fines when everything is contained in a single web form project.

What do I need to do to make it work from a class library?

Thanks,

Marcel

I used Visual Studio 2003 to create this ascx file:

<%@ Control Language="c#" AutoEventWireup ="false"
Codebehind="Web UserControl1.as cx.cs"
Inherits="WebCo ntrolLibrary1.W ebUserControl1"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The code behind file for the user control looks like this:

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebControlLibra ry1
{
/// <summary>
/// Summary description for WebUserControl1 .
/// </summary>
public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Butt on Button1;
protected System.Web.UI.W ebControls.Text Box TextBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void Button1_Click(o bject sender, System.EventArg s e)
{

}
}
}

The ASPX form looks like this:

<%@ Page language="c#" Codebehind="Web Form1.aspx.cs" AutoEventWireup ="false"
Inherits="WebAp plication1.WebF orm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebC ontrolLibrary1"
Assembly="WebCo ntrolLibrary1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
&nbsp;
<cc1:WebUserCon trol1 id="WebUserCont rol11"
runat="server"> </cc1:WebUserCont rol1>
</form>
</body>
</HTML>

and finally the code behind file for the web form:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{
protected WebControlLibra ry1.WebUserCont rol1 WebUserControl1 1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}

Nov 18 '05 #1
5 3156
user controls are meant to be a part of an application.
ie by design.
which means that if you have the use of control in more than one application
(web application project)
then you should create a web custom control. (not a user control)
http://msdn.microsoft.com/library/de...ebControls.asp
--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:9d******** ***********@ams news03.chello.c om...
Hi,

I am trying to create a User Control that is located in a seperate class
library. The User Control contains a textbox and a button.
The page generates an exception when it tries to access the code variable
that are supposed to be linked to the contained controls.

It runs fines when everything is contained in a single web form project.

What do I need to do to make it work from a class library?

Thanks,

Marcel

I used Visual Studio 2003 to create this ascx file:

<%@ Control Language="c#" AutoEventWireup ="false"
Codebehind="Web UserControl1.as cx.cs"
Inherits="WebCo ntrolLibrary1.W ebUserControl1"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The code behind file for the user control looks like this:

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebControlLibra ry1
{
/// <summary>
/// Summary description for WebUserControl1 .
/// </summary>
public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Butt on Button1;
protected System.Web.UI.W ebControls.Text Box TextBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void Button1_Click(o bject sender, System.EventArg s e)
{

}
}
}

The ASPX form looks like this:

<%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
AutoEventWireup ="false"
Inherits="WebAp plication1.WebF orm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebC ontrolLibrary1"
Assembly="WebCo ntrolLibrary1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
&nbsp;
<cc1:WebUserCon trol1 id="WebUserCont rol11"
runat="server"> </cc1:WebUserCont rol1>
</form>
</body>
</HTML>

and finally the code behind file for the web form:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{
protected WebControlLibra ry1.WebUserCont rol1 WebUserControl1 1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}

Nov 18 '05 #2
Hermit,

Ok, that would explain why my control fails.

Perhaps I should explain what I am trying to do here. I want to create some
common controls for toolbars, menu's and login that can be used across
serveral web apps. I also like to use Visual Studio for building the
control. I guess I want to throw some control on a custom control surface
and write some code, without having handle all the HTML rendering myself.

Any thoughts on that?

Thanks,

Marcel
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
user controls are meant to be a part of an application.
ie by design.
which means that if you have the use of control in more than one application (web application project)
then you should create a web custom control. (not a user control)
http://msdn.microsoft.com/library/de...ebControls.asp

--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:9d******** ***********@ams news03.chello.c om...
Hi,

I am trying to create a User Control that is located in a seperate class
library. The User Control contains a textbox and a button.
The page generates an exception when it tries to access the code variable that are supposed to be linked to the contained controls.

It runs fines when everything is contained in a single web form project.

What do I need to do to make it work from a class library?

Thanks,

Marcel

I used Visual Studio 2003 to create this ascx file:

<%@ Control Language="c#" AutoEventWireup ="false"
Codebehind="Web UserControl1.as cx.cs"
Inherits="WebCo ntrolLibrary1.W ebUserControl1"
TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The code behind file for the user control looks like this:

using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebControlLibra ry1
{
/// <summary>
/// Summary description for WebUserControl1 .
/// </summary>
public class WebUserControl1 : System.Web.UI.U serControl
{
protected System.Web.UI.W ebControls.Butt on Button1;
protected System.Web.UI.W ebControls.Text Box TextBox1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion

private void Button1_Click(o bject sender, System.EventArg s e)
{

}
}
}

The ASPX form looks like this:

<%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
AutoEventWireup ="false"
Inherits="WebAp plication1.WebF orm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebC ontrolLibrary1"
Assembly="WebCo ntrolLibrary1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1 </title>
<meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" Content="C#">
<meta name="vs_defaul tClientScript" content="JavaSc ript">
<meta name="vs_target Schema"
content="http://schemas.microso ft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
&nbsp;
<cc1:WebUserCon trol1 id="WebUserCont rol11"
runat="server"> </cc1:WebUserCont rol1>
</form>
</body>
</HTML>

and finally the code behind file for the web form:

using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.P age
{
protected WebControlLibra ry1.WebUserCont rol1 WebUserControl1 1;

private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
}

#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.Load += new System.EventHan dler(this.Page_ Load);

}
#endregion
}
}


Nov 18 '05 #3
nope cant do. atleast not the easy way.
if you want to use the spirit of vs.net you will have to settle for custom
web control. though you can use child objects within the control, instead of
having to write all the html

you do have way in which you can bypass and use user controls (you wanted to
drag and drop and just write some quick code) across applications. but again
thats not the most elegant solution. and you will have no visual studio.net
support.

here's what you do.. create a web application and put all your user controls
in that. for every application that needs to use it, you will have to
manually create a virtual directory that points to that app. Since vs.net
has no concept of server's virtual directory structure.. you dont have be
able to drag and drop from vs.net but you would still be able to use them.

--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:xn******** ************@am snews02.chello. com...
Hermit,

Ok, that would explain why my control fails.

Perhaps I should explain what I am trying to do here. I want to create
some
common controls for toolbars, menu's and login that can be used across
serveral web apps. I also like to use Visual Studio for building the
control. I guess I want to throw some control on a custom control surface
and write some code, without having handle all the HTML rendering myself.

Any thoughts on that?

Thanks,

Marcel
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:OB******** ******@TK2MSFTN GP12.phx.gbl...
user controls are meant to be a part of an application.
ie by design.
which means that if you have the use of control in more than one

application
(web application project)
then you should create a web custom control. (not a user control)

http://msdn.microsoft.com/library/de...ebControls.asp


--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:9d******** ***********@ams news03.chello.c om...
> Hi,
>
> I am trying to create a User Control that is located in a seperate
> class
> library. The User Control contains a textbox and a button.
> The page generates an exception when it tries to access the code variable > that are supposed to be linked to the contained controls.
>
> It runs fines when everything is contained in a single web form
> project.
>
> What do I need to do to make it work from a class library?
>
> Thanks,
>
> Marcel
>
> I used Visual Studio 2003 to create this ascx file:
>
> <%@ Control Language="c#" AutoEventWireup ="false"
> Codebehind="Web UserControl1.as cx.cs"
> Inherits="WebCo ntrolLibrary1.W ebUserControl1"
> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
> <asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>
> The code behind file for the user control looks like this:
>
> using System;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.UI.W ebControls;
> using System.Web.UI.H tmlControls;
>
> namespace WebControlLibra ry1
> {
> /// <summary>
> /// Summary description for WebUserControl1 .
> /// </summary>
> public class WebUserControl1 : System.Web.UI.U serControl
> {
> protected System.Web.UI.W ebControls.Butt on Button1;
> protected System.Web.UI.W ebControls.Text Box TextBox1;
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArg s e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeCompo nent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeCompo nent()
> {
> this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
> this.Load += new System.EventHan dler(this.Page_ Load);
>
> }
> #endregion
>
> private void Button1_Click(o bject sender, System.EventArg s e)
> {
>
> }
> }
> }
>
> The ASPX form looks like this:
>
> <%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
> AutoEventWireup ="false"
> Inherits="WebAp plication1.WebF orm1" %>
> <%@ Register TagPrefix="cc1" Namespace="WebC ontrolLibrary1"
> Assembly="WebCo ntrolLibrary1" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1 </title>
> <meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
> <meta name="CODE_LANG UAGE" Content="C#">
> <meta name="vs_defaul tClientScript" content="JavaSc ript">
> <meta name="vs_target Schema"
> content="http://schemas.microso ft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING= "GridLayout ">
> <form id="Form1" method="post" runat="server">
> &nbsp;
> <cc1:WebUserCon trol1 id="WebUserCont rol11"
> runat="server"> </cc1:WebUserCont rol1>
> </form>
> </body>
> </HTML>
>
> and finally the code behind file for the web form:
>
> using System;
> using System.Collecti ons;
> using System.Componen tModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.Sess ionState;
> using System.Web.UI;
> using System.Web.UI.W ebControls;
> using System.Web.UI.H tmlControls;
>
> namespace WebApplication1
> {
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.P age
> {
> protected WebControlLibra ry1.WebUserCont rol1 WebUserControl1 1;
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArg s e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeCompo nent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeCompo nent()
> {
> this.Load += new System.EventHan dler(this.Page_ Load);
>
> }
> #endregion
> }
> }
>
>
>



Nov 18 '05 #4
Hermit,

I was affraid I had do it the hard way. I think I will use the class derived
from WebControl and override the function CreateChildCont rols. This seams to
be the best way to build a composite control.

Marcel

"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl...
nope cant do. atleast not the easy way.
if you want to use the spirit of vs.net you will have to settle for custom
web control. though you can use child objects within the control, instead of having to write all the html

you do have way in which you can bypass and use user controls (you wanted to drag and drop and just write some quick code) across applications. but again thats not the most elegant solution. and you will have no visual studio.net support.

here's what you do.. create a web application and put all your user controls in that. for every application that needs to use it, you will have to
manually create a virtual directory that points to that app. Since vs.net
has no concept of server's virtual directory structure.. you dont have be
able to drag and drop from vs.net but you would still be able to use them.

--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:xn******** ************@am snews02.chello. com...
Hermit,

Ok, that would explain why my control fails.

Perhaps I should explain what I am trying to do here. I want to create
some
common controls for toolbars, menu's and login that can be used across
serveral web apps. I also like to use Visual Studio for building the
control. I guess I want to throw some control on a custom control surface
and write some code, without having handle all the HTML rendering myself.
Any thoughts on that?

Thanks,

Marcel
"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message news:OB******** ******@TK2MSFTN GP12.phx.gbl...
user controls are meant to be a part of an application.
ie by design.
which means that if you have the use of control in more than one

application
(web application project)
then you should create a web custom control. (not a user control)

http://msdn.microsoft.com/library/de...ebControls.asp


--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:9d******** ***********@ams news03.chello.c om...
> Hi,
>
> I am trying to create a User Control that is located in a seperate
> class
> library. The User Control contains a textbox and a button.
> The page generates an exception when it tries to access the code

variable
> that are supposed to be linked to the contained controls.
>
> It runs fines when everything is contained in a single web form
> project.
>
> What do I need to do to make it work from a class library?
>
> Thanks,
>
> Marcel
>
> I used Visual Studio 2003 to create this ascx file:
>
> <%@ Control Language="c#" AutoEventWireup ="false"
> Codebehind="Web UserControl1.as cx.cs"
> Inherits="WebCo ntrolLibrary1.W ebUserControl1"
> TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
> <asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>
> The code behind file for the user control looks like this:
>
> using System;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.UI.W ebControls;
> using System.Web.UI.H tmlControls;
>
> namespace WebControlLibra ry1
> {
> /// <summary>
> /// Summary description for WebUserControl1 .
> /// </summary>
> public class WebUserControl1 : System.Web.UI.U serControl
> {
> protected System.Web.UI.W ebControls.Butt on Button1;
> protected System.Web.UI.W ebControls.Text Box TextBox1;
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArg s e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeCompo nent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeCompo nent()
> {
> this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
> this.Load += new System.EventHan dler(this.Page_ Load);
>
> }
> #endregion
>
> private void Button1_Click(o bject sender, System.EventArg s e)
> {
>
> }
> }
> }
>
> The ASPX form looks like this:
>
> <%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
> AutoEventWireup ="false"
> Inherits="WebAp plication1.WebF orm1" %>
> <%@ Register TagPrefix="cc1" Namespace="WebC ontrolLibrary1"
> Assembly="WebCo ntrolLibrary1" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1 </title>
> <meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
> <meta name="CODE_LANG UAGE" Content="C#">
> <meta name="vs_defaul tClientScript" content="JavaSc ript">
> <meta name="vs_target Schema"
> content="http://schemas.microso ft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING= "GridLayout ">
> <form id="Form1" method="post" runat="server">
> &nbsp;
> <cc1:WebUserCon trol1 id="WebUserCont rol11"
> runat="server"> </cc1:WebUserCont rol1>
> </form>
> </body>
> </HTML>
>
> and finally the code behind file for the web form:
>
> using System;
> using System.Collecti ons;
> using System.Componen tModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.Sess ionState;
> using System.Web.UI;
> using System.Web.UI.W ebControls;
> using System.Web.UI.H tmlControls;
>
> namespace WebApplication1
> {
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.P age
> {
> protected WebControlLibra ry1.WebUserCont rol1 WebUserControl1 1;
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArg s e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeCompo nent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeCompo nent()
> {
> this.Load += new System.EventHan dler(this.Page_ Load);
>
> }
> #endregion
> }
> }
>
>
>



Nov 18 '05 #5
good luck with that... if you need any help you can always come around here
.... a better place would be
microsoft.publi c.dotnet.framew ork.aspnet.buil dingcontrols
or
microsoft.publi c.dotnet.framew ork.aspnet.webc ontrols

--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:2B******** ************@am snews02.chello. com...
Hermit,

I was affraid I had do it the hard way. I think I will use the class
derived
from WebControl and override the function CreateChildCont rols. This seams
to
be the best way to build a composite control.

Marcel

"Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message
news:up******** ******@tk2msftn gp13.phx.gbl...
nope cant do. atleast not the easy way.
if you want to use the spirit of vs.net you will have to settle for
custom
web control. though you can use child objects within the control, instead

of
having to write all the html

you do have way in which you can bypass and use user controls (you wanted

to
drag and drop and just write some quick code) across applications. but

again
thats not the most elegant solution. and you will have no visual

studio.net
support.

here's what you do.. create a web application and put all your user

controls
in that. for every application that needs to use it, you will have to
manually create a virtual directory that points to that app. Since vs.net
has no concept of server's virtual directory structure.. you dont have be
able to drag and drop from vs.net but you would still be able to use
them.

--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
news:xn******** ************@am snews02.chello. com...
> Hermit,
>
> Ok, that would explain why my control fails.
>
> Perhaps I should explain what I am trying to do here. I want to create
> some
> common controls for toolbars, menu's and login that can be used across
> serveral web apps. I also like to use Visual Studio for building the
> control. I guess I want to throw some control on a custom control surface > and write some code, without having handle all the HTML rendering myself. >
> Any thoughts on that?
>
> Thanks,
>
> Marcel
>
>
> "Hermit Dave" <he************ @CAPS.AND.DOTS. hotmail.com> wrote in message > news:OB******** ******@TK2MSFTN GP12.phx.gbl...
>> user controls are meant to be a part of an application.
>> ie by design.
>> which means that if you have the use of control in more than one
> application
>> (web application project)
>> then you should create a web custom control. (not a user control)
>>
> http://msdn.microsoft.com/library/de...ebControls.asp >>
>>
>> --
>> Regards,
>> HD
>> Once a Geek.... Always a Geek
>> "Marcel Gelijk" <mg*****@hotmai l.com> wrote in message
>> news:9d******** ***********@ams news03.chello.c om...
>> > Hi,
>> >
>> > I am trying to create a User Control that is located in a seperate
>> > class
>> > library. The User Control contains a textbox and a button.
>> > The page generates an exception when it tries to access the code
> variable
>> > that are supposed to be linked to the contained controls.
>> >
>> > It runs fines when everything is contained in a single web form
>> > project.
>> >
>> > What do I need to do to make it work from a class library?
>> >
>> > Thanks,
>> >
>> > Marcel
>> >
>> > I used Visual Studio 2003 to create this ascx file:
>> >
>> > <%@ Control Language="c#" AutoEventWireup ="false"
>> > Codebehind="Web UserControl1.as cx.cs"
>> > Inherits="WebCo ntrolLibrary1.W ebUserControl1"
>> > TargetSchema="h ttp://schemas.microso ft.com/intellisense/ie5" %>
>> > <asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
>> > <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>> >
>> > The code behind file for the user control looks like this:
>> >
>> > using System;
>> > using System.Data;
>> > using System.Drawing;
>> > using System.Web;
>> > using System.Web.UI.W ebControls;
>> > using System.Web.UI.H tmlControls;
>> >
>> > namespace WebControlLibra ry1
>> > {
>> > /// <summary>
>> > /// Summary description for WebUserControl1 .
>> > /// </summary>
>> > public class WebUserControl1 : System.Web.UI.U serControl
>> > {
>> > protected System.Web.UI.W ebControls.Butt on Button1;
>> > protected System.Web.UI.W ebControls.Text Box TextBox1;
>> >
>> > private void Page_Load(objec t sender, System.EventArg s e)
>> > {
>> > // Put user code to initialize the page here
>> > }
>> >
>> > #region Web Form Designer generated code
>> > override protected void OnInit(EventArg s e)
>> > {
>> > //
>> > // CODEGEN: This call is required by the ASP.NET Web Form
>> > Designer.
>> > //
>> > InitializeCompo nent();
>> > base.OnInit(e);
>> > }
>> >
>> > /// <summary>
>> > /// Required method for Designer support - do not modify
>> > /// the contents of this method with the code editor.
>> > /// </summary>
>> > private void InitializeCompo nent()
>> > {
>> > this.Button1.Cl ick += new System.EventHan dler(this.Butto n1_Click);
>> > this.Load += new System.EventHan dler(this.Page_ Load);
>> >
>> > }
>> > #endregion
>> >
>> > private void Button1_Click(o bject sender, System.EventArg s e)
>> > {
>> >
>> > }
>> > }
>> > }
>> >
>> > The ASPX form looks like this:
>> >
>> > <%@ Page language="c#" Codebehind="Web Form1.aspx.cs"
>> > AutoEventWireup ="false"
>> > Inherits="WebAp plication1.WebF orm1" %>
>> > <%@ Register TagPrefix="cc1" Namespace="WebC ontrolLibrary1"
>> > Assembly="WebCo ntrolLibrary1" %>
>> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>> > <HTML>
>> > <HEAD>
>> > <title>WebForm1 </title>
>> > <meta name="GENERATOR " Content="Micros oft Visual Studio .NET 7.1">
>> > <meta name="CODE_LANG UAGE" Content="C#">
>> > <meta name="vs_defaul tClientScript" content="JavaSc ript">
>> > <meta name="vs_target Schema"
>> > content="http://schemas.microso ft.com/intellisense/ie5">
>> > </HEAD>
>> > <body MS_POSITIONING= "GridLayout ">
>> > <form id="Form1" method="post" runat="server">
>> > &nbsp;
>> > <cc1:WebUserCon trol1 id="WebUserCont rol11"
>> > runat="server"> </cc1:WebUserCont rol1>
>> > </form>
>> > </body>
>> > </HTML>
>> >
>> > and finally the code behind file for the web form:
>> >
>> > using System;
>> > using System.Collecti ons;
>> > using System.Componen tModel;
>> > using System.Data;
>> > using System.Drawing;
>> > using System.Web;
>> > using System.Web.Sess ionState;
>> > using System.Web.UI;
>> > using System.Web.UI.W ebControls;
>> > using System.Web.UI.H tmlControls;
>> >
>> > namespace WebApplication1
>> > {
>> > /// <summary>
>> > /// Summary description for WebForm1.
>> > /// </summary>
>> > public class WebForm1 : System.Web.UI.P age
>> > {
>> > protected WebControlLibra ry1.WebUserCont rol1 WebUserControl1 1;
>> >
>> > private void Page_Load(objec t sender, System.EventArg s e)
>> > {
>> > // Put user code to initialize the page here
>> > }
>> >
>> > #region Web Form Designer generated code
>> > override protected void OnInit(EventArg s e)
>> > {
>> > //
>> > // CODEGEN: This call is required by the ASP.NET Web Form
>> > Designer.
>> > //
>> > InitializeCompo nent();
>> > base.OnInit(e);
>> > }
>> >
>> > /// <summary>
>> > /// Required method for Designer support - do not modify
>> > /// the contents of this method with the code editor.
>> > /// </summary>
>> > private void InitializeCompo nent()
>> > {
>> > this.Load += new System.EventHan dler(this.Page_ Load);
>> >
>> > }
>> > #endregion
>> > }
>> > }
>> >
>> >
>> >
>>
>>
>
>



Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1262
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file. called A One project that build a user control dll called B One project that build a class library dll called C In the constructor for this user control is a call to a method in the class library. public (){
4
1688
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
5
1944
by: Tony Johansson | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. Here we have a class called B One project that build a class library dll. Here we have a class called C We have one dependency and that is from the user control to the class library because in the constructor for class B in the user control we have a call to
0
1753
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class called B One project that build a class library dll. In this class library we have a class called C In the user control project I have a project reference to the class library.
1
1535
by: Tony Johansson | last post by:
Hello!! I use VS 2003 and C#. I have sent several mail even tried with crossgroup because I want to find out if my problem is a bug in .NET or if .NET doesn't support what I do. It's only one of these left I suppose. I use project reference where a need to.
1
2457
by: Tony Johansson | last post by:
Hello!! I use VS 2003 and C#. I have sent several mail even tried with crossgroup because I want to find out if my problem is a bug in .NET or if .NET doesn't support what I do. It's only one of these left I suppose. I use project reference where a need to.
0
3935
by: tony | last post by:
Hello! This is a rather long mail but it's a very interesting one. I hope you read it. I have tried several times to get an answer to this mail but I have not get any answer saying something like this is a bug or that .NET doesn't support what I trying to do. I hope that one that is is microsoft certified read this because this must be a bug.
5
1927
by: =?Utf-8?B?U2FsYW1FbGlhcw==?= | last post by:
Hi, I have a user control which I like to use in several projects (winforms) in the same solution. Inside lets say Winapp1 , When adding a reference to this control, I can dynamically or statically create it and when running the application it is correctly drawn on the form. But when I take out the reference to this control in Winapp1, reference it in a utility project, then reference the utility project in Winapp1 or Winapp2, instantiate...
10
2139
by: =?Utf-8?B?RGFuaQ==?= | last post by:
Hi, Trying to create a master page that holds a menu, and the menu switches between pages in the site. 2 problem arrosed: a. When I navigate from page to page (all AJAX Web Forms, with the Master pages as their master...) the entire page is refreshed - also the menu which belongs to the master, how can I fix it - so only the inside content will be refreshed ?
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.