I'm attempting to create a custom calendar control that inherits from ASP.Net's built in calendar user control.
the code-behind file for my control looks like this:
public partial class WeeklyEventsCalendar : Calendar
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
and compiles fine.
However, when I try to place my custom control on an aspx page:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testbed.aspx.cs" Inherits="testbed" %>
<%@ Register Src="UserControls/WeeklyEventsCalendar.ascx" TagName="WeeklyEventsCalendar"
TagPrefix="mvs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<link href="~/css/VitalSignsStyleSheet.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div>
<mvs:WeeklyEventsCalendar runat="server" />
</div>
</body>
</html>
I get a warning 'Element WeeklyEventsCalendar is not a known element. This can occur if there is a compilation error in the web site, or the web.config file is missing.' Attempting
I don't get any sort of 'file not found' error like I have in the past when I mis-typed the location of the file.
When I attempt to load aspx page in a browser, I get error CS0115: 'ASP.usercontrols_weeklyeventscalendar_ascx.FrameworkInitialize()': no suitable method found to override
Which is even more confusing, because nowhere in my code do I attempt to define such a function.
This should be really simple. Where am I going wrong?
I think the problem is that you're attempting to inherit the Calendar control (which is a server control) from a user control (based on your ASCX extension). You can't do this. If you want to inherit from the Calendar control then you need to create a server control.
Let me know if you need some sample code.
Bryant hit on it. One thing you might consider if all you're doing is customizing the existing control is embedding an instance of the calendar on your user control and exposing the properties you need from it. This way your user control can handle all of the requisite customizations, and also provide only a limited interface back out to the consuming application. (This is composition instead of inheritance.)
If you really do need to fully derive from asp:Calendar, then you need to create a standard class which derives from the Calendar control, and then perform your customizations. You'll have no UI design for that, however -- everything you do will need to be custom code. (And if you need to change the HTML being emitted, you'll need to write those custom streams out as well -- which, with a calendar control, could be painful.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With