" + x + "\")'>" + x + "</a>";";
DHTMLFunction += " calText = calText + '</td>'; ";
DHTMLFunction += " } ";
DHTMLFunction += " if (((firstDay+x) % 7) == 0) ";
DHTMLFunction += " { ";
DHTMLFunction += " calText = calText + '</tr><tr>'; ";
DHTMLFunction += " } ";
DHTMLFunction += " } ";
DHTMLFunction += " calText = calText + '</tr>';";
DHTMLFunction += " calText = calText + '</table></td></tr></table>';";
DHTMLFunction += " var CalendarSpan = document.all(calname);";
DHTMLFunction += " if (CalendarSpan != null)";
DHTMLFunction += " CalendarSpan.innerHTML = calText;";
DHTMLFunction += " var CalendarValue = document.all(calname + '_CurrentDate');";
DHTMLFunction += " if (CalendarValue != null)";
DHTMLFunction += " CalendarValue.value = ' + (CurrentDate.getMonth() + 1) + '/' + CurrentDate.getDate() + '/' + CurrentDate.getFullYear();";
DHTMLFunction += " } ";
DHTMLFunction += "</script> ";
if (Page.Request.UserAgent.IndexOf("MSIE 5.5") != -1)
Page.RegisterClientScriptBlock("ACME_CALENDAR_DHTML", DHTMLFunction);
}
protected void RenderDownLevel(HtmlTextWriter output)
{
// Output Calendar Header
output.WriteLine("<table bgcolor=" + backColor + " border=0 height=190 valign=top><tr><td>");
output.WriteLine("<table bgcolor=" + backColor + " border=0 height=190 valign=top>");
output.WriteLine("<tr><td>");
output.WriteLine("<center>");
output.WriteLine(" <a href="javascript:" + Page.GetPostBackEventReference(this, "NavPrevMonth") + "">");
output.WriteLine("<img src=/quickstart/aspplus/images/left4.gif width=11 height=11 border=0></a>");
output.WriteLine(" <b>" + monthNames[currentDate.Month-1] + " " + Int32.Format(currentDate.Year, null) + "</b>");
output.WriteLine(" <a href="javascript:" + Page.GetPostBackEventReference(this, "NavNextMonth") + "">");
output.WriteLine("<IMG SRC=/quickstart/aspplus/images/right4.gif width=11 height=11 border=0></a>");
output.WriteLine("</center>");
output.WriteLine("</td></tr>");
output.WriteLine("<tr valign=top><td valign=top>");
output.WriteLine("<table border=1 bgcolor=" + foreColor + " height=160>");
output.WriteLine("<tr height=20>");
output.WriteLine(" <td align=right width=23> Sun </td>");
output.WriteLine(" <td align=right width=23> Mon </td>");
output.WriteLine(" <td align=right width=23> Tue </td>");
output.WriteLine(" <td align=right width=23> Wed </td>");
output.WriteLine(" <td align=right width=23> Thu </td>");
output.WriteLine(" <td align=right width=23> Fri </td>");
output.WriteLine(" <td align=right width=23> Sat </td>");
output.WriteLine("</tr>");
output.WriteLine("<tr>");
// Calculate how many days are in the month
int numDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
// Calculate what day of week the first day of the month is on
int firstDay = new DateTime(currentDate.Year, currentDate.Month, 1).DayOfWeek;
// Pre-Day Padding
for (int x=0; x<firstDay; x++)
{
output.WriteLine("<td align=right width=23></td>");
}
// Output each day
for (int x=1; x<=numDays; x++)
{
if (currentDate.Day == x)
{
output.Write("<td align=right width=23>");
output.Write("<font color=red><b><u>" + Int32.Format(x, null) + "</u></b></font>");
output.WriteLine("</td>");
}
else
{
output.Write("<td align=right width=23>");
output.Write("<a href="javascript:" + Page.GetPostBackEventReference(this, Int32.Format(x, null)) + "">");
output.Write(Int32.Format(x, null) + "</a>");
output.WriteLine("</td>");
}
// PerPage row break as appropriate
if (((firstDay+x) % 7) == 0)
{
output.WriteLine("</tr><tr>");
}
}
output.WriteLine("</tr>");
output.WriteLine("</table></td></tr></table></table>");
}
public DateTime Date
{
get
{
return currentDate;
}
set
{
currentDate = value;
}
}
public String BackColor
{
get
{
return backColor;
}
set
{
backColor = value;
}
}
public String ForeColor
{
get
{
return foreColor;
}
set
{
foreColor = value;
}
}
// Todo: We should eliminate the need for a control developer to do stub
// implementations of the below standard IPostDataHandler Methods
public bool LoadPostData(String postDataKey, NameValueCollection values)
{
String clientDate = values[UniqueID + "_CurrentDate"];
if (clientDate != null)
currentDate = DateTime.Parse(clientDate);
return false;
}
public void RaisePostDataChangedEvent()
{
}
}
}
生成服务器控件的文件
csc /t:library /r:System.Web.dll /r:System.dll /out:......inAcme.dll Acme.cs
csc /t:library /out:......inWebMarket.dll WebMarket.cs
这个例子的演示在
http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro7.aspx
这个日历的服务器控件可以同时支持高级和低级的浏览器,对于高级的浏览器,他在客户端生成DHTML 代码,DHTML 文档不需要和服务器进行交互!对于低级的浏览器,则生成标准的 HTML 3.2 的代码,这个时候需要和服务器的交互来处理浏览器客户端的用户操作
注意:这个页面的代码的开发者在书写的过程中,开发者不需要关心客户浏览器是高级的还是低级的。日历控件自己会处理两种浏览器之间的差别
下一讲,我们将要进入asp+ 操作 数据库 的章节,请大家随时留意我们的站点更新!
DHTMLFunction += " calText = calText + '</td>'; ";
DHTMLFunction += " } ";
DHTMLFunction += " if (((firstDay+x) % 7) == 0) ";
DHTMLFunction += " { ";
DHTMLFunction += " calText = calText + '</tr><tr>'; ";
DHTMLFunction += " } ";
DHTMLFunction += " } ";
DHTMLFunction += " calText = calText + '</tr>';";
DHTMLFunction += " calText = calText + '</table></td></tr></table>';";
DHTMLFunction += " var CalendarSpan = document.all(calname);";
DHTMLFunction += " if (CalendarSpan != null)";
DHTMLFunction += " CalendarSpan.innerHTML = calText;";
DHTMLFunction += " var CalendarValue = document.all(calname + '_CurrentDate');";
DHTMLFunction += " if (CalendarValue != null)";
DHTMLFunction += " CalendarValue.value = ' + (CurrentDate.getMonth() + 1) + '/' + CurrentDate.getDate() + '/' + CurrentDate.getFullYear();";
DHTMLFunction += " } ";
DHTMLFunction += "</script> ";
if (Page.Request.UserAgent.IndexOf("MSIE 5.5") != -1)
Page.RegisterClientScriptBlock("ACME_CALENDAR_DHTML", DHTMLFunction);
}
protected void RenderDownLevel(HtmlTextWriter output)
{
// Output Calendar Header
output.WriteLine("<table bgcolor=" + backColor + " border=0 height=190 valign=top><tr><td>");
output.WriteLine("<table bgcolor=" + backColor + " border=0 height=190 valign=top>");
output.WriteLine("<tr><td>");
output.WriteLine("<center>");
output.WriteLine(" <a href="javascript:" + Page.GetPostBackEventReference(this, "NavPrevMonth") + "">");
output.WriteLine("<img src=/quickstart/aspplus/images/left4.gif width=11 height=11 border=0></a>");
output.WriteLine(" <b>" + monthNames[currentDate.Month-1] + " " + Int32.Format(currentDate.Year, null) + "</b>");
output.WriteLine(" <a href="javascript:" + Page.GetPostBackEventReference(this, "NavNextMonth") + "">");
output.WriteLine("<IMG SRC=/quickstart/aspplus/images/right4.gif width=11 height=11 border=0></a>");
output.WriteLine("</center>");
output.WriteLine("</td></tr>");
output.WriteLine("<tr valign=top><td valign=top>");
output.WriteLine("<table border=1 bgcolor=" + foreColor + " height=160>");
output.WriteLine("<tr height=20>");
output.WriteLine(" <td align=right width=23> Sun </td>");
output.WriteLine(" <td align=right width=23> Mon </td>");
output.WriteLine(" <td align=right width=23> Tue </td>");
output.WriteLine(" <td align=right width=23> Wed </td>");
output.WriteLine(" <td align=right width=23> Thu </td>");
output.WriteLine(" <td align=right width=23> Fri </td>");
output.WriteLine(" <td align=right width=23> Sat </td>");
output.WriteLine("</tr>");
output.WriteLine("<tr>");
// Calculate how many days are in the month
int numDays = DateTime.DaysInMonth(currentDate.Year, currentDate.Month);
// Calculate what day of week the first day of the month is on
int firstDay = new DateTime(currentDate.Year, currentDate.Month, 1).DayOfWeek;
// Pre-Day Padding
for (int x=0; x<firstDay; x++)
{
output.WriteLine("<td align=right width=23></td>");
}
// Output each day
for (int x=1; x<=numDays; x++)
{
if (currentDate.Day == x)
{
output.Write("<td align=right width=23>");
output.Write("<font color=red><b><u>" + Int32.Format(x, null) + "</u></b></font>");
output.WriteLine("</td>");
}
else
{
output.Write("<td align=right width=23>");
output.Write("<a href="javascript:" + Page.GetPostBackEventReference(this, Int32.Format(x, null)) + "">");
output.Write(Int32.Format(x, null) + "</a>");
output.WriteLine("</td>");
}
// PerPage row break as appropriate
if (((firstDay+x) % 7) == 0)
{
output.WriteLine("</tr><tr>");
}
}
output.WriteLine("</tr>");
output.WriteLine("</table></td></tr></table></table>");
}
public DateTime Date
{
get
{
return currentDate;
}
set
{
currentDate = value;
}
}
public String BackColor
{
get
{
return backColor;
}
set
{
backColor = value;
}
}
public String ForeColor
{
get
{
return foreColor;
}
set
{
foreColor = value;
}
}
// Todo: We should eliminate the need for a control developer to do stub
// implementations of the below standard IPostDataHandler Methods
public bool LoadPostData(String postDataKey, NameValueCollection values)
{
String clientDate = values[UniqueID + "_CurrentDate"];
if (clientDate != null)
currentDate = DateTime.Parse(clientDate);
return false;
}
public void RaisePostDataChangedEvent()
{
}
}
}
生成服务器控件的文件
csc /t:library /r:System.Web.dll /r:System.dll /out:......inAcme.dll Acme.cs
csc /t:library /out:......inWebMarket.dll WebMarket.cs
这个例子的演示在
http://tutorial.superexpert.com/quickstart/aspplus/samples/webforms/intro/intro7.aspx
这个日历的服务器控件可以同时支持高级和低级的浏览器,对于高级的浏览器,他在客户端生成DHTML 代码,DHTML 文档不需要和服务器进行交互!对于低级的浏览器,则生成标准的 HTML 3.2 的代码,这个时候需要和服务器的交互来处理浏览器客户端的用户操作
注意:这个页面的代码的开发者在书写的过程中,开发者不需要关心客户浏览器是高级的还是低级的。日历控件自己会处理两种浏览器之间的差别
下一讲,我们将要进入asp+ 操作 数据库 的章节,请大家随时留意我们的站点更新!