我正在嘗試使用來自多個來源的代碼構建我自己的日期選擇器。具體來說,我現在試圖讓asp:按鈕顯示/隱藏日曆。ASP按鈕調用JavaScript函數
我在做什麼錯?
myDate.ascx
<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="myDate.ascx.vb"
Inherits="Website.myDate" %>
<script language="javascript" type="text/javascript">
function toggleCalendar(myID) {
var obj = document.getElementById(myID)
obj.style.display = (obj.style.display == "none") ? "" : "none";
}
</script>
<asp:TextBox ID="dateText" runat="server" > </asp:TextBox>
<asp:Button ID="dateBtn" runat="server" UseSubmitBehavior="false" Text="x" />
<asp:Calendar ID="dateCal" runat="server" >
</asp:Calendar>
myDate.ascx.vb爲按鈕
Partial Public Class myDate
Inherits System.Web.UI.UserControl
Protected Sub Page_Load
(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Add OnClick event to call JavaScript to toggle calendar display'
calBtn.Attributes.Add("OnClick", "toggleCalendar(" & cal.ClientID & ")")
End Sub
End Class
HTML代碼(從瀏覽器)
<input type="button" name="ctl03$calBtn" value="x"
onclick="toggleCalendar(ctl03_cal);__doPostBack('ctl03$calBtn','')"
id="ctl03_calBtn" />
謝謝!完美工作。我剛開始時(在進行用戶控制之前),我只是不知道<%=CODE%>語法。 – Steven 2010-04-08 16:50:39