DayRenderEventArgs.SelectUrl 屬性

定義

取得當 Calendar 控制項中選取了正在呈現的日期後,用來將頁面回傳至伺服器的指令碼。

public:
 property System::String ^ SelectUrl { System::String ^ get(); };
public string SelectUrl { get; }
member this.SelectUrl : string
Public ReadOnly Property SelectUrl As String

屬性值

String

當選取了正在呈現的日期後,用來將頁面回傳至伺服器的指令碼。

範例

下列程式碼範例示範如何自訂為今天日期轉譯的內容。 屬性的值 SelectUrl 會插入轉譯的內容中, Calendar 以便當使用者選取今天日期時,控制項會回傳至伺服器。

<!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 選取要轉譯的日期時,將頁面張貼回伺服器。 當您想要自訂針對日期轉譯的內容,但仍想要保留回傳行為時,通常會使用這個屬性。

適用於

另請參閱