[英]Trying to load an ASP textbox with HTML5 input type=Date element
I'm trying to use the new HTML5 input type=date to load and asp:textbox with the date value. 我正在尝试使用新的HTML5输入type = date加载,并将asp:textbox与日期值一起使用。 I either get nothing (empty label) back or I get (System.Web.UI.WebControls.TextBox).
我要么一无所获(空标签),要么得到(System.Web.UI.WebControls.TextBox)。 I'm trying just to use the HTML5 date input type.
我正在尝试仅使用HTML5日期输入类型。 Don't know if the problem is in my javascript or where.
不知道问题出在我的JavaScript中还是在哪里。 The user will: 1. select they're birthdate via the html5 datepicker.
用户将:1.通过html5 datepicker选择生日。 2. The user clicks the submit button 3. at which time the datepicker has lost focus 4. The javascript function "onblur" should kick in 5. The asp:textbox "tbDOB" should get loaded with the date 6. That date gets' sent back back to server.
2.用户单击“提交”按钮。3.此时,日期选择器失去了焦点。4. javascript函数“ onblur”应开始运行。5. asp:textbox“ tbDOB”应被加载日期6。发送回服务器。
7. At that point for verification purposes the date should update the lblDateReturn label. 7.出于验证目的,该日期应更新lblDateReturn标签。
Thanks Suge 谢谢S
<div id="dpDOB">
<asp:TextBox ID="tbDOB" runat="server"></asp:TextBox><br />
<input type="date" id="dpDatePicker" onblur="blurFunction()" required /><br />
<asp:Button ID="btnDOB" runat="server" Text="Submit" OnClick="btnDOB_Click()" /><br/>
<asp:Label ID="lblDateReturn" runat="server" Text=""></asp:Label>
</div>
function blurFunction()
{
var dateofBirth = document.getElementById("tbDOB"); //asp.net textbox
var datepicker = document.getElementById("dbDatePicker");
dateofBirth.value = datepicker.value; // Trying to load the asp.net textbox with the date
alert("Date Picker lost focus");
}
protected void btnDOB_Click(object sender, EventArgs e)
{
//lblDateReturn.Text = tbDOB.Text; blank lable
lblDateReturn.Text = tbDOB.ToString(); //I get back: System.Web.UI.WebControls.TextBox
}
用下面的行更改blurFunction()
的第一行:
var dateofBirth = document.getElementById("<%=tbDOB.ClientID%>");
The fix/solution, 修复/解决方案,
HTML5 type date: HTML5类型日期:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="dpDOB">
<asp:TextBox ID="tbDOB" runat="server"></asp:TextBox><br />
<input type="date" id="dpDatePicker" onblur="blurFunction()" required /><br />
<asp:Button ID="btnDOB" runat="server" Text="Submit" OnClick="btnDOB_Click"/> <br />
<asp:Label ID="lblDateReturn" runat="server" Text=""></asp:Label>
</div>
</asp:Content>
Java Script: Java脚本:
function blurFunction()
{
var datepicker = document.getElementById("dpDatePicker");
(document.getElementById("ContentPlaceHolder1_tbDOB")).value = datepicker.value;
}
C#: C#:
protected void btnDOB_Click(object sender, EventArgs e)
{
lblDateReturn.Text = tbDOB.Text;
}
CSS3: CSS3:
#ContentPlaceHolder1_tbDOB
{
display: none; //Hiding the textbox to make it appear the HTML5 type (date) picker is the only control
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.