ASP.NET Calendar 隱藏的問題(必須要有物件)

本來單純的想說
簡單的做一下日期控制
應該不用Ajax
就使用工具箱的Calendar 控制項
    <asp:TextBox ID="txtDate" runat="server" Width="88px" />
做日期的點選後
再隱藏就好
    <asp:Calendar ID="Calendar1" runat="server"

        BackColor="#FFFFCC" BorderColor="#FFCC66" BorderWidth="1px"
        DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
        ForeColor="#663399" Height="200px" ShowGridLines="True" Width="220px"  >
    <DayHeaderStyle BackColor="#FFCC66" Font-Bold="True" Height="1px" />
    <NextPrevStyle Font-Size="9pt" ForeColor="#FFFFCC" />
    <OtherMonthDayStyle ForeColor="#CC9966" />
    <SelectedDayStyle BackColor="#CCCCFF" Font-Bold="True" />
    <SelectorStyle BackColor="#FFCC66" />
    <TitleStyle BackColor="#990000" Font-Bold="True" Font-Size="9pt"
        ForeColor="#FFFFCC" />
    <TodayDayStyle BackColor="#FFCC66" ForeColor="White" />
    </asp:Calendar>

code behind
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim myScript As String = Nothing
            myScript += "<script type='text/javascript'>"
            myScript += "    function iniDisplay(tmpObj,tmpVal) {"
            myScript += "        var objID = document.getElementById(tmpObj);"
            myScript += "        objID.style.display = tmpVal;}"
            myScript += "</script>"
            '不能使用 Add 須使用 RegisterStartupScript
            'Page.Controls.Add(New LiteralControl(myScript))
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "onload", myScript)

            If (Not Page.ClientScript.IsStartupScriptRegistered("alert")) Then
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "iniDisplay('CalendarDisp','none');", True)
            End If

            txtDate.Attributes.Add("onclick", "iniDisplay('CalendarDisp','');")
        End If
    End Sub

    Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
        txtDate.Text = Format(Calendar1.SelectedDate, "yyyyMMdd")

        If (Not Page.ClientScript.IsStartupScriptRegistered("alert")) Then
            Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "iniDisplay('CalendarDisp','none');", True)
        End If
    End Sub
在點選日期時
結果發生了這個錯誤
想說一開始
即然就能隱藏跟彈出
沒有道理點選後再隱藏,就失效了......@#$%
將 myScript 的 iniDisplay 移出 aspx 再測試一下
嘿嘿嘿...收工,但真是搞不懂

程式下載

沒有留言:

張貼留言