By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,723 Members | 1,255 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,723 IT Pros & Developers. It's quick & easy.

Using User Control from class library

P: n/a
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="WebUserControl1.ascx.cs"
Inherits="WebControlLibrary1.WebUserControl1"
TargetSchema="http://schemas.microsoft.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.WebControls;
using System.Web.UI.HtmlControls;

namespace WebControlLibrary1
{
/// <summary>
/// Summary description for WebUserControl1.
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{

}
}
}

The ASPX form looks like this:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="WebApplication1.WebForm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
Assembly="WebControlLibrary1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
&nbsp;
<cc1:WebUserControl1 id="WebUserControl11"
runat="server"></cc1:WebUserControl1>
</form>
</body>
</HTML>

and finally the code behind file for the web form:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected WebControlLibrary1.WebUserControl1 WebUserControl11;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

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

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

}
#endregion
}
}

Nov 18 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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*****@hotmail.com> wrote in message
news:9d*******************@amsnews03.chello.com...
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="WebUserControl1.ascx.cs"
Inherits="WebControlLibrary1.WebUserControl1"
TargetSchema="http://schemas.microsoft.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.WebControls;
using System.Web.UI.HtmlControls;

namespace WebControlLibrary1
{
/// <summary>
/// Summary description for WebUserControl1.
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{

}
}
}

The ASPX form looks like this:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="WebApplication1.WebForm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
Assembly="WebControlLibrary1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
&nbsp;
<cc1:WebUserControl1 id="WebUserControl11"
runat="server"></cc1:WebUserControl1>
</form>
</body>
</HTML>

and finally the code behind file for the web form:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected WebControlLibrary1.WebUserControl1 WebUserControl11;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

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

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

}
#endregion
}
}

Nov 18 '05 #2

P: n/a
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**************@TK2MSFTNGP12.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*****@hotmail.com> wrote in message
news:9d*******************@amsnews03.chello.com...
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="WebUserControl1.ascx.cs"
Inherits="WebControlLibrary1.WebUserControl1"
TargetSchema="http://schemas.microsoft.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.WebControls;
using System.Web.UI.HtmlControls;

namespace WebControlLibrary1
{
/// <summary>
/// Summary description for WebUserControl1.
/// </summary>
public class WebUserControl1 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox1;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

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

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{

}
}
}

The ASPX form looks like this:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false"
Inherits="WebApplication1.WebForm1" %>
<%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
Assembly="WebControlLibrary1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
&nbsp;
<cc1:WebUserControl1 id="WebUserControl11"
runat="server"></cc1:WebUserControl1>
</form>
</body>
</HTML>

and finally the code behind file for the web form:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication1
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected WebControlLibrary1.WebUserControl1 WebUserControl11;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

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

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

}
#endregion
}
}


Nov 18 '05 #3

P: n/a
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*****@hotmail.com> wrote in message
news:xn********************@amsnews02.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**************@TK2MSFTNGP12.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*****@hotmail.com> wrote in message
news:9d*******************@amsnews03.chello.com...
> 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="WebUserControl1.ascx.cs"
> Inherits="WebControlLibrary1.WebUserControl1"
> TargetSchema="http://schemas.microsoft.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.WebControls;
> using System.Web.UI.HtmlControls;
>
> namespace WebControlLibrary1
> {
> /// <summary>
> /// Summary description for WebUserControl1.
> /// </summary>
> public class WebUserControl1 : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.Button Button1;
> protected System.Web.UI.WebControls.TextBox TextBox1;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Button1.Click += new System.EventHandler(this.Button1_Click);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
>
> private void Button1_Click(object sender, System.EventArgs e)
> {
>
> }
> }
> }
>
> The ASPX form looks like this:
>
> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
> AutoEventWireup="false"
> Inherits="WebApplication1.WebForm1" %>
> <%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
> Assembly="WebControlLibrary1" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> &nbsp;
> <cc1:WebUserControl1 id="WebUserControl11"
> runat="server"></cc1:WebUserControl1>
> </form>
> </body>
> </HTML>
>
> and finally the code behind file for the web form:
>
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
>
> namespace WebApplication1
> {
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.Page
> {
> protected WebControlLibrary1.WebUserControl1 WebUserControl11;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
> }
> }
>
>
>



Nov 18 '05 #4

P: n/a
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 CreateChildControls. 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**************@tk2msftngp13.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*****@hotmail.com> wrote in message
news:xn********************@amsnews02.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**************@TK2MSFTNGP12.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*****@hotmail.com> wrote in message
news:9d*******************@amsnews03.chello.com...
> 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="WebUserControl1.ascx.cs"
> Inherits="WebControlLibrary1.WebUserControl1"
> TargetSchema="http://schemas.microsoft.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.WebControls;
> using System.Web.UI.HtmlControls;
>
> namespace WebControlLibrary1
> {
> /// <summary>
> /// Summary description for WebUserControl1.
> /// </summary>
> public class WebUserControl1 : System.Web.UI.UserControl
> {
> protected System.Web.UI.WebControls.Button Button1;
> protected System.Web.UI.WebControls.TextBox TextBox1;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Button1.Click += new System.EventHandler(this.Button1_Click);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
>
> private void Button1_Click(object sender, System.EventArgs e)
> {
>
> }
> }
> }
>
> The ASPX form looks like this:
>
> <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
> AutoEventWireup="false"
> Inherits="WebApplication1.WebForm1" %>
> <%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
> Assembly="WebControlLibrary1" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
> <HTML>
> <HEAD>
> <title>WebForm1</title>
> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
> <meta name="CODE_LANGUAGE" Content="C#">
> <meta name="vs_defaultClientScript" content="JavaScript">
> <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </HEAD>
> <body MS_POSITIONING="GridLayout">
> <form id="Form1" method="post" runat="server">
> &nbsp;
> <cc1:WebUserControl1 id="WebUserControl11"
> runat="server"></cc1:WebUserControl1>
> </form>
> </body>
> </HTML>
>
> and finally the code behind file for the web form:
>
> using System;
> using System.Collections;
> using System.ComponentModel;
> using System.Data;
> using System.Drawing;
> using System.Web;
> using System.Web.SessionState;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.HtmlControls;
>
> namespace WebApplication1
> {
> /// <summary>
> /// Summary description for WebForm1.
> /// </summary>
> public class WebForm1 : System.Web.UI.Page
> {
> protected WebControlLibrary1.WebUserControl1 WebUserControl11;
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
>
> #region Web Form Designer generated code
> override protected void OnInit(EventArgs e)
> {
> //
> // CODEGEN: This call is required by the ASP.NET Web Form Designer.
> //
> InitializeComponent();
> base.OnInit(e);
> }
>
> /// <summary>
> /// Required method for Designer support - do not modify
> /// the contents of this method with the code editor.
> /// </summary>
> private void InitializeComponent()
> {
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
> #endregion
> }
> }
>
>
>



Nov 18 '05 #5

P: n/a
good luck with that... if you need any help you can always come around here
.... a better place would be
microsoft.public.dotnet.framework.aspnet.buildingc ontrols
or
microsoft.public.dotnet.framework.aspnet.webcontro ls

--
Regards,
HD
Once a Geek.... Always a Geek
"Marcel Gelijk" <mg*****@hotmail.com> wrote in message
news:2B********************@amsnews02.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 CreateChildControls. 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**************@tk2msftngp13.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*****@hotmail.com> wrote in message
news:xn********************@amsnews02.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**************@TK2MSFTNGP12.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*****@hotmail.com> wrote in message
>> news:9d*******************@amsnews03.chello.com...
>> > 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="WebUserControl1.ascx.cs"
>> > Inherits="WebControlLibrary1.WebUserControl1"
>> > TargetSchema="http://schemas.microsoft.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.WebControls;
>> > using System.Web.UI.HtmlControls;
>> >
>> > namespace WebControlLibrary1
>> > {
>> > /// <summary>
>> > /// Summary description for WebUserControl1.
>> > /// </summary>
>> > public class WebUserControl1 : System.Web.UI.UserControl
>> > {
>> > protected System.Web.UI.WebControls.Button Button1;
>> > protected System.Web.UI.WebControls.TextBox TextBox1;
>> >
>> > private void Page_Load(object sender, System.EventArgs e)
>> > {
>> > // Put user code to initialize the page here
>> > }
>> >
>> > #region Web Form Designer generated code
>> > override protected void OnInit(EventArgs e)
>> > {
>> > //
>> > // CODEGEN: This call is required by the ASP.NET Web Form
>> > Designer.
>> > //
>> > InitializeComponent();
>> > base.OnInit(e);
>> > }
>> >
>> > /// <summary>
>> > /// Required method for Designer support - do not modify
>> > /// the contents of this method with the code editor.
>> > /// </summary>
>> > private void InitializeComponent()
>> > {
>> > this.Button1.Click += new System.EventHandler(this.Button1_Click);
>> > this.Load += new System.EventHandler(this.Page_Load);
>> >
>> > }
>> > #endregion
>> >
>> > private void Button1_Click(object sender, System.EventArgs e)
>> > {
>> >
>> > }
>> > }
>> > }
>> >
>> > The ASPX form looks like this:
>> >
>> > <%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
>> > AutoEventWireup="false"
>> > Inherits="WebApplication1.WebForm1" %>
>> > <%@ Register TagPrefix="cc1" Namespace="WebControlLibrary1"
>> > Assembly="WebControlLibrary1" %>
>> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
>> > <HTML>
>> > <HEAD>
>> > <title>WebForm1</title>
>> > <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
>> > <meta name="CODE_LANGUAGE" Content="C#">
>> > <meta name="vs_defaultClientScript" content="JavaScript">
>> > <meta name="vs_targetSchema"
>> > content="http://schemas.microsoft.com/intellisense/ie5">
>> > </HEAD>
>> > <body MS_POSITIONING="GridLayout">
>> > <form id="Form1" method="post" runat="server">
>> > &nbsp;
>> > <cc1:WebUserControl1 id="WebUserControl11"
>> > runat="server"></cc1:WebUserControl1>
>> > </form>
>> > </body>
>> > </HTML>
>> >
>> > and finally the code behind file for the web form:
>> >
>> > using System;
>> > using System.Collections;
>> > using System.ComponentModel;
>> > using System.Data;
>> > using System.Drawing;
>> > using System.Web;
>> > using System.Web.SessionState;
>> > using System.Web.UI;
>> > using System.Web.UI.WebControls;
>> > using System.Web.UI.HtmlControls;
>> >
>> > namespace WebApplication1
>> > {
>> > /// <summary>
>> > /// Summary description for WebForm1.
>> > /// </summary>
>> > public class WebForm1 : System.Web.UI.Page
>> > {
>> > protected WebControlLibrary1.WebUserControl1 WebUserControl11;
>> >
>> > private void Page_Load(object sender, System.EventArgs e)
>> > {
>> > // Put user code to initialize the page here
>> > }
>> >
>> > #region Web Form Designer generated code
>> > override protected void OnInit(EventArgs e)
>> > {
>> > //
>> > // CODEGEN: This call is required by the ASP.NET Web Form
>> > Designer.
>> > //
>> > InitializeComponent();
>> > base.OnInit(e);
>> > }
>> >
>> > /// <summary>
>> > /// Required method for Designer support - do not modify
>> > /// the contents of this method with the code editor.
>> > /// </summary>
>> > private void InitializeComponent()
>> > {
>> > this.Load += new System.EventHandler(this.Page_Load);
>> >
>> > }
>> > #endregion
>> > }
>> > }
>> >
>> >
>> >
>>
>>
>
>



Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.