I have been trying to make a simple server control. but it doesn't work. Can someone take a look and give me a hint? the code is probably OK but the way I use those files is probably wrong. I just put them both in 1 folder and then go to the "simple.aspx"
file with my browser.
I have an "simple.aspx" page and a "simple.vb" file.
the simple.vb file should be the server control.
Imports
System
Imports System.Web
Imports System.Web.UI
Namespace SimpleControlSamples
Public Class SimpleVB :
Inherits Control
Protected Overrides
Sub Render(Output
As HtmlTextWriter)
Output.Write("<H2>Welcome to Control Development!</H2>")
End Sub
End Class
End Namespace
I think I have to make a .dll of the .vb file and put it in the bin folder of my web application. I have visual studio 2005 standard edition. how do I make a .DLL of the simple.aspx file?
The Assembly attribute should be the name of Project (usually the DLL name too). This is where your error is.
Tag prefix looks OK could be anything you like - if a bit long
Your namespace looks OK.
Here is an example I posted somewhere else earlier today. Its C# VS2005, but you should be able to follow it and use the information.
This is my custom control class. I simply extend an existing one - so not much work. Its in a separate project called "CustomCalendar". This is also the name of the DLL referenced by the web project that uses it (below)
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
namespace
Pixelda.CustomCalendar
{
public
class MyCustomCalendar :
Calendar
{
public
object VisibleDateCustom
{
get
{
if (!Enabled)
return
null;
else
return VisibleDate;
}
set
{
if (value ==
null)
Enabled = false;
else
VisibleDate = (Convert.ToDateTime(value));
}
}
}
}
Here is the web page with the REGISTER tag. The web site is in a separate project and references the custom project above to form a solution (it cold jus reference the DLL's though)
interwandere...
Contributor
2693 Points
542 Posts
simple server control
Dec 07, 2005 12:52 PM|LINK
Hello,
I have been trying to make a simple server control. but it doesn't work. Can someone take a look and give me a hint? the code is probably OK but the way I use those files is probably wrong. I just put them both in 1 folder and then go to the "simple.aspx" file with my browser.
I have an "simple.aspx" page and a "simple.vb" file.
the simple.vb file should be the server control.
Imports
SystemImports System.Web
Imports System.Web.UI
Namespace SimpleControlSamples
Public Class SimpleVB : Inherits Control
Protected Overrides Sub Render(Output As HtmlTextWriter)
Output.Write("<H2>Welcome to Control Development!</H2>")
End Sub
End Class
End Namespace
the simple. aspx file:
<%
@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %><
html> <body> <form id="Form1" method="POST" action="Simple.aspx" runat=server> <SimpleControlSamples:SimpleVB id="MyControl" runat=server/> </form> </body></
html>I get an error on this line:
<%
@ Register TagPrefix="SimpleControlSamples" Namespace="SimpleControlSamples" Assembly="SimpleControlSamplesVB" %>I think I have to make a .dll of the .vb file and put it in the bin folder of my web application. I have visual studio 2005 standard edition. how do I make a .DLL of the simple.aspx file?
thx in advance,
.one of my (older) projects social tomorrow and
sbyard
Contributor
5891 Points
1196 Posts
Re: simple server control
Dec 07, 2005 02:07 PM|LINK
The Assembly attribute should be the name of Project (usually the DLL name too). This is where your error is.
Tag prefix looks OK could be anything you like - if a bit long
Your namespace looks OK.
Here is an example I posted somewhere else earlier today. Its C# VS2005, but you should be able to follow it and use the information.
This is my custom control class. I simply extend an existing one - so not much work. Its in a separate project called "CustomCalendar". This is also the name of the DLL referenced by the web project that uses it (below)
using
System;using
System.Data;using
System.Configuration;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls;namespace
Pixelda.CustomCalendar{
public class MyCustomCalendar : Calendar{
public object VisibleDateCustom
{
get
{
if (!Enabled)
return null;
else
return VisibleDate;
}
set
{
if (value == null)
Enabled = false;
else
VisibleDate = (Convert.ToDateTime(value));
}
}
}
}
Here is the web page with the REGISTER tag. The web site is in a separate project and references the custom project above to form a solution (it cold jus reference the DLL's though)
<%@ Page Language="C#" %>
<%@ Register Assembly="CustomCalendar" TagPrefix="pix" Namespace="Pixelda.CustomCalendar" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
script runat="server">protected void Page_Load(object sender, EventArgs e)
{
CustCal1.VisibleDateCustom = DateTime.Now;
}
protected void Button1_Click(object sender, EventArgs e)
{
CustCal1.VisibleDateCustom = null;
}
</
script><
html xmlns="http://www.w3.org/1999/xhtml"><
head runat="server"><title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="SetDateNull" OnClick="Button1_Click" />
<div>
<pix:MyCustomCalendar runat="server" ID="CustCal1" />
</div>
</form>
</body>
</html>