Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have this content page, and, I would like to include a calendar control, so I randomly :) tried the following, code and got a few errors.

Any workarounds, please?

<![CDATA[<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Diary.aspx.cs" Inherits="Diary" Title="Untitled Page" %>]]>

<asp:content id="Content1" contentplaceholderid="head" runat="Server" xmlns:asp="#unknown">
<asp:calendar id="Calendar1" runat="server"></asp:calendar>
//it's a bug including the control here (VS 2008) :confused:
</asp:content>
<asp:calendar id="Calendar1" runat="server" xmlns:asp="#unknown"></asp:calendar>
<asp:content id="Content2" contentplaceholderid="body" runat="Server" xmlns:asp="#unknown">
//it's a bug including the control here (VS 2008) :confused:
This page is still under construction.
    
</asp:content>


Errors
1. Error 1 Only Content controls are allowed directly in a content page that contains Content controls. c:\inetpub\wwwroot\Jon's Couch\Default.aspx 3

2. Warning 2 c:\inetpub\wwwroot\Jon's Couch\Diary.aspx: ASP.NET runtime error: Only Content controls are allowed directly in a content page that contains Content controls. c:\inetpub\wwwroot\Jon's Couch\Diary.aspx 5 1 http://localhost/Jon's Couch/

3. Warning 3 Validation (ASP.Net): Content is not supported outside 'script' or 'asp:content' regions. c:\inetpub\wwwroot\Jon's Couch\Diary.aspx 5 6 http://localhost/Jon's Couch/

4. Jon's Couch (ASP.NET 3.5; armani)

5. Source code (excluding this error here.
Posted
Updated 17-Aug-10 3:45am
v2

Assuming that you have implemented the modification suggestion to your existing code problems as said here : http://www.codeproject.com/Answers/102443/newbie-navigation-problems.aspx#answer1[^]

Modify the code for Diary.aspx as follows:

XML
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Diary.aspx.cs" Inherits="Diary" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</asp:Content>


This should show you a nice calendar in the browser :)

By the way, randomly writing codes and trying different things is not the correct idea of learning programming and doing things. You need to try to understand first what you are trying to do and learn how to do those with the programming platform/tool you are going to use. Google is your best friend.

Best of luck :)
 
Share this answer
 
Comments
jon-80 17-Aug-10 11:32am    
hmm...doesn't work, because I get an error reading that I need to place the calendar within tags, and, it seems that it is not possible to place them within a content page.

diary.aspx
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</asp:Content>


Error displayed when I select My Diary (lhs)

Server Error in '/Jon's Couch' Application.

Control 'ctl00_body_Calendar1' of type 'Calendar' must be placed inside a form tag with runat=server.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Control 'ctl00_body_Calendar1' of type 'Calendar' must be placed inside a form tag with runat=server.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Control 'ctl00_body_Calendar1' of type 'Calendar' must be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +8689827
System.Web.UI.WebControls.Calendar.Render(HtmlTextWriter writer) +147
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266


A tag cannot be placed within the ContentPlaceHolder, because it seems to conflict with the tag within the MasterPage, MasterPage.master.
Al-Farooque Shubho 17-Aug-10 11:42am    
Well, it should work. Please do the followings:

1. Copy the MasterPage codes from http://www.codeproject.com/Answers/102443/newbie-navigation-problems.aspx#answer1 (The previous answer)

I know, you already copied. But please, copy again, because, it had a silly problem in the MasterPage code and I modified it later. You may have copied before I corrected the problem and hence you are getting the error

2. Then try the code that I have given here already

I just tested the page and the Calendar is working fine. Please let me know
jon-80 17-Aug-10 15:01pm    
well it must be that my workhorse running Win XP SP3 over .NET Framework 3.5 (+3.5 SP1) doesn't like the control, coz I'm still getting the same error. What environment are you using?
Al-Farooque Shubho 17-Aug-10 22:25pm    
I don't think the OS and the framework should be the problem. Please send me the source code (or, upload somewhere and give link). I'll try to correct it.
You're using master pages. All code needs to be wrapped in content controls.

<code>
<asp:content id="theId1" runat="server" contentplaceholderid="fromMasterPage1">

<!-- put your content here -->

</asp:content>

<!-- don't put anything here -->

<asp:content id="theId2" runat="server" contentplaceholderid="fromMasterPage2">

<!-- put your content here -->
</asp:content>
</code>

If you're still having trouble:
- Make sure your content controls reference content placeholder ids from the master page correctly
- Make sure you have closing tags for your
- Simplify and just try with just text boxes.
 
Share this answer
 
v2
Comments
TheyCallMeMrJames 17-Aug-10 10:30am    
can't get formatting to work...
jon-80 17-Aug-10 15:03pm    
I'll see what I can figure out with text boxes, it would be nice if I could get a custom control, because actually that was my original intention; create a calendar that is linked to a database, which triggers data being loaded in a journal like fashion, however I am still thinking out how to go about it.

Are you using .NET 3.5 as well?
TheyCallMeMrJames 17-Aug-10 15:19pm    
I'm on 3.5 + 4.0 right now, depending on the day/project. Be sure to consider jQuery/jQuery UI as it will simplify a ton of your client side development. Shameless plug: have a look at my profile and check out my imported blog articles.
And anyway, how do I get fancy custom controls, like calendars and user controls showing up within my content?

:confused:
 
Share this answer
 
Comments
TheyCallMeMrJames 17-Aug-10 15:20pm    
jQuery and jQuery UI. http://theycallmemrjames.blogspot.com/p/aspnet-mvc-and-jquery.html
Make sure there are no errors in your web.config file.
It sometimes happens when you are referencing an assembly in web.config and it does not exists in the bin folder
e.g. AjaxToolKit.dll
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900