DayRenderEventArgs.SelectUrl 属性
定义
public:
property System::String ^ SelectUrl { System::String ^ get(); };
public string SelectUrl { get; }
member this.SelectUrl : string
Public ReadOnly Property SelectUrl As String
属性值
选择呈现的日期时用于将此页回发至服务器的脚本。The script used to post the page back to the server when the date being rendered is selected.
示例
下面的代码示例演示如何自定义为今天的日期呈现的内容。The following code example demonstrates how to customize the content rendered for today's date. 属性的值将 SelectUrl 插入到呈现的内容中,以便在 Calendar 用户选择当天的日期时,控件将回发到服务器。The value of the SelectUrl property is inserted into the rendered content so that the Calendar control will post back to the server when the user selects today's date.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void ScheduleCalendar_DayRender(object sender, DayRenderEventArgs e)
{
// Customize the caption for today's date.
if(e.Day.IsToday)
{
// Create the content to render for today's date. Use the
// SelectUrl property to retrieve the script used to post
// the page back to the server when the user selects the
// date.
string dayContent = "<a href=\"" + e.SelectUrl +
"\"><img border=\"0\" alt=\"Today\" src=\"today.jpg\"/></a>";
// Display the custom content in the date cell.
e.Cell.Text = dayContent;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:calendar id="ScheduleCalendar"
ondayrender="ScheduleCalendar_DayRender"
runat="server"/>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub ScheduleCalendar_DayRender(ByVal sender As Object, ByVal e As DayRenderEventArgs) Handles ScheduleCalendar.DayRender
' Customize the caption for today's date.
If e.Day.IsToday Then
' Create the content to render for today's date. Use the
' SelectUrl property to retrieve the script used to post
' the page back to the server when the user selects the
' date.
Dim dayContent As String = "<a href=""" & e.SelectUrl & _
"""><img border=""0"" alt=""Today"" src=""today.jpg""/></a>"
' Display the custom content in the date cell.
e.Cell.Text = dayContent
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:calendar id="ScheduleCalendar"
runat="server"/>
</form>
</body>
</html>
注解
使用 SelectUrl 属性可检索在控件中选择呈现的日期时用于将页面回发到服务器的脚本 Calendar 。Use the SelectUrl property to retrieve the script used to post the page back to the server when the date being rendered is selected in a Calendar control. 如果要自定义为日期呈现的内容,但仍希望保留回发行为,通常使用此属性。This property is typically used when you want to customize the content rendered for a date, but still want to retain the postback behavior.