This message was discovered on ASPFriends.com 'aspngfreeforall' list.
| Thomas Stone |
Hi All,
I have successfully used the Calendar control in the past, but now I am experiencing some odd behavior from it.
First, sometimes (inconsistent, it seems) the Next and Prev month links don't work -- they produce client side errors that read "Invalid Syntax", and claims the problem is in the JavaScript produced, which is:
<script language="javascript"> <!-- function __doPostBack(eventTarget, eventArgument) { var theform = document._ctl0; theform.__EVENTTARGET.value = eventTarget; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // --> </script>
The error says the problem is in the last line: theform.submit();
The call to this function in the link is: javascript:__doPostBack('Calendar1','V974')
Any ideas?
Second, I am displaying data from an Access database in this calendar. Because it wasn't obvious to me how to just do this automatically with a DataReader, I am getting a DataReader out, and then creating an array with the data, and then using that array to populate the calendar. The code is below, and it works fine.
Question: Why does my calendar often show an entire additional row of days -- the first week of the next month -- even when there are no dates from the current calendar month in that week? It shouldn't do this.
Question: While building my array of data I am also building a string with that data (the events for the current month). I then display this HTML string below the calendar (it has additional details not shown in the little calendar boxes). But for some crazy reason this data below the calendar is for the next month!!! If it is now August, the August events will properly display in the calendar, but my string below will list all the September month details!
If you can tell me how to more directly get data from a DataReader into my calendar -- instead of using an array -- (and into my string for display in a div.InnerHtml), then that would be great too.
Any help?
Thanks,
Tom Stone
public class MainEven : System.Web.UI.Page { protected System.Web.UI.WebControls.Calendar Calendar1; protected System.Web.UI.HtmlControls.HtmlSelect JumpMonth; protected System.Web.UI.HtmlControls.HtmlSelect JumpYear; public HtmlGenericControl FurtherInfo; string[] caldays = new string[32];
public void Page_Load(object sender, System.EventArgs e) { string strMonth; string strYear;
if (IsPostBack == false) { strMonth = System.DateTime.Now.Month.ToString(); strYear = System.DateTime.Now.Year.ToString(); GetData(strMonth, strYear); }
else if (IsPostBack == true) { string strJumpMonth = ""; strJumpMonth = JumpMonth.Value; string strJumpYear = ""; strJumpYear = JumpYear.Value;
GetData(strJumpMonth, strJumpYear); }
}
public void GetData(string strMonth, string strYear) { string strCurrent = strMonth + "/%/" + strYear;
string strSQL = "SELECT * FROM Events WHERE Start LIKE '" + strCurrent + "' ORDER BY Start ASC";
string strDBLocation; strDBLocation = Server.MapPath("../cgi-bin/profs.mdb"); OleDbConnection objConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + strDBLocation); objConn.Open(); OleDbCommand objCommand = new OleDbCommand(strSQL, objConn);
OleDbDataReader objDR; objDR = objCommand.ExecuteReader();
for (int i = 1; i < 32; i++) { caldays[i] = ""; }
string strData = "<h3>Further information:</h3>";
while (objDR.Read()) { string strCurr = objDR["Start"].ToString(); DateTime dtCurr = Convert.ToDateTime(strCurr); int intCurr = dtCurr.Day; caldays[intCurr] += objDR["ShortTitle"] + " (" + objDR["Duration"] + ")<br><br>"; strData += "<p><b>" + objDR["LongTitle"] + "</b><br><a href='" + objDR["URL"] + "'>" + objDR["URL"] + "</a><br>";
if (objDR["Parent"].ToString() != "") { strData += "<b>Organization:</b> " + objDR["Parent"] + "<br>"; }
if (objDR["State"].ToString() != "") { strData += "<b>State/Province:</b> " + objDR["State"] + " "; } string strStart = objDR["Start"].ToString(); DateTime dtStart = Convert.ToDateTime(strStart); string strStartDate = dtStart.Month.ToString() + "/" + dtStart.Day.ToString() + "/" + dtStart.Year.ToString();
string strEnd = objDR["End"].ToString(); DateTime dtEnd = Convert.ToDateTime(strEnd); string strEndDate = dtEnd.Month.ToString() + "/" + dtEnd.Day.ToString() + "/" + dtEnd.Year.ToString();
strData += "<b>Country:</b> " + objDR["Country"] + "<br><b>Start Date: </b>" + strStartDate + " <b>End Date: </b>" + strEndDate + "<br>";
if (objDR["Description"].ToString() != "") { strData += "<b>Description:</b> " + objDR["Description"] + "<br>"; }
strData += "</p>";
}
FurtherInfo.InnerHtml = strData;
objDR.Close(); objConn.Close();
}
public void Calendar1_DayRender(Object source, DayRenderEventArgs e) {
CalendarDay d; TableCell c; d = e.Day;
GetData(e.Day.Date.Month.ToString(), e.Day.Date.Year.ToString());
c = e.Cell; string strEvent = caldays[d.Date.Day]; if (strEvent != "") { c.Controls.Add(new LiteralControl("<br>" + strEvent)); } }
public void Calendar1_MonthChange(Object source, MonthChangedEventArgs e) { GetData(e.NewDate.Month.ToString(), e.NewDate.Year.ToString()); }
#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 }
|
|
| |
| |
| chris |
Give your form an id. maybe the javascript is confused over naming something in its DOM with a value that begins with _.
-Chris Frazier .NET Solution Developer Velocity Databank, Inc. www.velocitydatabank.com
-----Original Message----- From: Thomas Stone [mailto:Click here to reveal e-mail address] Sent: Friday, August 09, 2002 7:52 AM To: aspngfreeforall Subject: [aspngfreeforall] Calendar Control -- Odd/Error Behaviors?
Hi All,
I have successfully used the Calendar control in the past, but now I am experiencing some odd behavior from it.
First, sometimes (inconsistent, it seems) the Next and Prev month links don't work -- they produce client side errors that read "Invalid Syntax", and claims the problem is in the JavaScript produced, which is:
<script language="javascript"> <!-- function __doPostBack(eventTarget, eventArgument) { var theform = document._ctl0; theform.__EVENTTARGET.value = eventTarget; theform.__EVENTARGUMENT.value = eventArgument; theform.submit(); } // --> </script>
The error says the problem is in the last line: theform.submit();
The call to this function in the link is: javascript:__doPostBack('Calendar1','V974')
Any ideas?
Second, I am displaying data from an Access database in this calendar. Because it wasn't obvious to me how to just do this automatically with a DataReader, I am getting a DataReader out, and then creating an array with the data, and then using that array to populate the calendar. The code is below, and it works fine.
Question: Why does my calendar often show an entire additional row of days -- the first week of the next month -- even when there are no dates from the current calendar month in that week? It shouldn't do this.
Question: While building my array of data I am also building a string with that data (the events for the current month). I then display this HTML string below the calendar (it has additional details not shown in the little calendar boxes). But for some crazy reason this data below the calendar is for the next month!!! If it is now August, the August events will properly display in the calendar, but my string below will list all the September month details!
If you can tell me how to more directly get data from a DataReader into my calendar -- instead of using an array -- (and into my string for display in a div.InnerHtml), then that would be great too.
Any help?
Thanks,
Tom Stone
public class MainEven : System.Web.UI.Page { protected System.Web.UI.WebControls.Calendar Calendar1; protected System.Web.UI.HtmlControls.HtmlSelect JumpMonth; protected System.Web.UI.HtmlControls.HtmlSelect JumpYear; public HtmlGenericControl FurtherInfo; string[] caldays = new string[32];
public void Page_Load(object sender, System.EventArgs e) { string strMonth; string strYear;
if (IsPostBack == false) { strMonth = System.DateTime.Now.Month.ToString(); strYear = System.DateTime.Now.Year.ToString(); GetData(strMonth, strYear); }
else if (IsPostBack == true) { string strJumpMonth = ""; strJumpMonth = JumpMonth.Value; string strJumpYear = ""; strJumpYear = JumpYear.Value;
GetData(strJumpMonth, strJumpYear); }
}
public void GetData(string strMonth, string strYear) {
string strCurrent = strMonth + "/%/" + strYear;
string strSQL = "SELECT * FROM Events WHERE Start LIKE '" + strCurrent + "' ORDER BY Start ASC";
string strDBLocation; strDBLocation = Server.MapPath("../cgi-bin/profs.mdb"); OleDbConnection objConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" + strDBLocation); objConn.Open();
OleDbCommand objCommand = new OleDbCommand(strSQL, objConn);
OleDbDataReader objDR; objDR = objCommand.ExecuteReader();
for (int i = 1; i < 32; i++) { caldays[i] = ""; }
string strData = "<h3>Further information:</h3>";
while (objDR.Read()) { string strCurr = objDR["Start"].ToString(); DateTime dtCurr = Convert.ToDateTime(strCurr); int intCurr = dtCurr.Day; caldays[intCurr] += objDR["ShortTitle"] + " (" + objDR["Duration"] + ")<br><br>"; strData += "<p><b>" + objDR["LongTitle"] + "</b><br><a href='" + objDR["URL"] + "'>" + objDR["URL"] + "</a><br>";
if (objDR["Parent"].ToString() != "") { strData += "<b>Organization:</b> " + objDR["Parent"] + "<br>"; }
if (objDR["State"].ToString() != "") { strData += "<b>State/Province:</b> " + objDR["State"] + " "; }
string strStart = objDR["Start"].ToString(); DateTime dtStart = Convert.ToDateTime(strStart); string strStartDate = dtStart.Month.ToString() + "/" + dtStart.Day.ToString() + "/" + dtStart.Year.ToString();
string strEnd = objDR["End"].ToString(); DateTime dtEnd = Convert.ToDateTime(strEnd); string strEndDate = dtEnd.Month.ToString() + "/" + dtEnd.Day.ToString() + "/" + dtEnd.Year.ToString();
strData += "<b>Country:</b> " + objDR["Country"] + "<br><b>Start Date: </b>" + strStartDate + " <b>End Date: </b>" + strEndDate + "<br>";
if (objDR["Description"].ToString() != "") { strData += "<b>Description:</b> " + objDR["Description"] + "<br>"; }
strData += "</p>";
}
FurtherInfo.InnerHtml = strData;
objDR.Close(); objConn.Close();
}
public void Calendar1_DayRender(Object source, DayRenderEventArgs e) {
CalendarDay d; TableCell c; d = e.Day;
GetData(e.Day.Date.Month.ToString(), e.Day.Date.Year.ToString());
c = e.Cell; string strEvent = caldays[d.Date.Day]; if (strEvent != "") { c.Controls.Add(new LiteralControl("<br>" + strEvent)); }
}
public void Calendar1_MonthChange(Object source, MonthChangedEventArgs e) { GetData(e.NewDate.Month.ToString(), e.NewDate.Year.ToString()); }
#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 }
| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/aspngfreeforall = JOIN/QUIT | news://ls.asplists.com = NEWSGROUP
|
|
| |
|
| |
| Thomas Stone |
An interesting idea, but that didn't work.
I have two other calendars that very similar, and they are working -- without an id for their web form. The only major difference I can see between the ones I have working and the one that is not, is that the Calendar1_MonthChange event handler in this case calls a function that takes two string parameters (month and year), instead of just one. But that shouldn't have anything to do with the *client side* error I am getting.... not to mention the other two odd behaviors I am seeing.
-- Tom S.
At 09:19 AM 8/9/2002 -0500, you wrote: [Original message clipped]
|
|
| |
|
| |
| TomMallard |
OK, you can't submit the form, so, to debug use a display of the datatype of your elements.
alert(typeOf(document._ctl0.__EVENTARGUMENT));
This will allow you to find out what's up.
tom mallard seattle
-----Original Message----- From: Thomas Stone [mailto:Click here to reveal e-mail address] Sent: Friday, August 09, 2002 11:38 AM To: aspngfreeforall Subject: [aspngfreeforall] RE: Calendar Control -- Odd/Error Behaviors?
An interesting idea, but that didn't work.
I have two other calendars that very similar, and they are working -- without an id for their web form. The only major difference I can see between the ones I have working and the one that is not, is that the Calendar1_MonthChange event handler in this case calls a function that takes two string parameters (month and year), instead of just one. But that shouldn't have anything to do with the *client side* error I am getting.... not to mention the other two odd behaviors I am seeing.
-- Tom S.
At 09:19 AM 8/9/2002 -0500, you wrote: >Give your form an id. maybe the javascript is confused over naming something [Original message clipped]
| ASP.net DOCS = http://www.aspng.com/docs | [aspngfreeforall] member Click here to reveal e-mail address = YOUR ID | http://www.asplists.com/aspngfreeforall = JOIN/QUIT | news://ls.asplists.com = NEWSGROUP
|
|
| |
|
| |
| Dan Satria |
[Original message clipped]
As I browsed through the months, it seems like the calendar control always displays 6 rows (weeks) of dates. It becomes apparent why this is necessary since a month may consist of up to 31 days which is 4 weeks and 3 days. Unfortunately, the extra days don't necessarily fall into a week. For example, October 2004 has the first two days in a week, and the last day on a separate week. Therefore, Oct 2004 needs 6 weeks.
I also noticed that your DayRender code does not display the data correctly. You use d.Date.Day for an index into CalDays. This value is always within 1..31 regardless whether the day is on previous or next month. For example for June 2004, the first day on the calendar is May 30 which d.Date.Day will return 30. However, CalDays[30] is June 30th, not May 30th.
I added if (!d.IsOtherMonth) before adding the string to the cell to prevent it from displaying erroneous info.
I hope this helps.
Dan Satria
-------------------------------- From: Dan Satria
|
|
| |
|
|
|
|
|