I have included the source code. This fails everytime. This problem shouldn't be as hard as it is, but if someone could give me a good solution I would be greatly happy.
PS The code needs to be ran in a project because simply looking at the code doesnt describe the problem. The error that I get says that the "Page cannot be null". I need a pros help! And yes! If someone gets me an answer that works ill send you a check for 50 American Dollars. Scouts honor.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
int i = 1;
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
TextBox t = new TextBox();
t.ID = "t" + i;
e.Cell.Controls.Add(t);
MaskedEditExtender mee1 = new MaskedEditExtender();
mee1.AcceptAMPM = true;
mee1.Mask = "99:99";
mee1.MaskType = MaskedEditType.Time;
mee1.TargetControlID = t.ID;
mee1.ClearMaskOnLostFocus = false;
mee1.ClientIDMode = System.Web.UI.ClientIDMode.Static;
mee1.ID = "MaskedEditExtender" + i++;
e.Cell.Controls.Add(mee1);
}
}
}
Loading
Sam HobbsPosted Apr 20, 2011, 12:13 AM
As far as I can tell, the Calendar.DayRender event happens once for each day in the calendar. So I assume you don't want to do "Page.Controls.Add"; that seems incorrect to me. So perhaps Suthish meant something else.
Justin NPosted Apr 19, 2011, 3:21 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
int i = 1;
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
TextBox t = new TextBox();
t.ID = "t" + i;
Page.Controls.Add(t); // Added this line
e.Cell.Controls.Add(t);
MaskedEditExtender mee1 = new MaskedEditExtender();
mee1.AcceptAMPM = true;
mee1.Mask = "99:99";
mee1.MaskType = MaskedEditType.Time;
mee1.TargetControlID = t.ID;
mee1.ClearMaskOnLostFocus = false;
mee1.ClientIDMode = System.Web.UI.ClientIDMode.Static;
mee1.ID = "MaskedEditExtender" + i++;
Page.Controls.Add(mee1); // and this line
e.Cell.Controls.Add(mee1);
}
}
}
here's the markup, master page has nothing extra added to it.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
Suthish NairPosted Apr 18, 2011, 2:56 PM