473,732 Members | 2,214 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 3159
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
1263
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
1754
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
1929
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
8774
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,...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
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
6735
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
6031
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();...
1
3261
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
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
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.