简体   繁体   English

尝试使用HTML5输入type = Date元素加载ASP文本框

[英]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, 修复/解决方案,

  1. I neglected to post that I am using a master page (my bad) which changed the id of the ASP textbox from "tbDOB" to "ContentPlaceHolder1_tbDOB". 我忽略发布我正在使用一个母版页(我的错),该页将ASP文本框的ID从“ tbDOB”更改为“ ContentPlaceHolder1_tbDOB”。

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.

相关问题 如何在更改时关闭日期选择器 <input type=“date” /> HTML5输入日期元素 - How to close the date picker on change for <input type=“date” /> HTML5 Input date element "<i>HTML5<\/i> HTML5<\/b><input type=“date”> <i>- onChange Event<\/i> - onChange 事件<\/b>" - HTML5 <input type=“date”> - onChange Event 尝试使用源元素加载 HTML5 视频时检测错误类型 - Detect the type of error when trying to load a HTML5 video using a source element HTML5输入类型date:如何制作日期字符串 - HTML5 input type date: how to make the date string 从chrome中输入HTML5输入[type =“date”]的输入值 - Get input value from HTML5 input[type=“date”] in chrome 指定HTML5输入类型=日期的值输出? - Specifying the value output of of an HTML5 input type = date? Html5 javascript gettime()来自 <input type=“date” /> ,奇怪的工作 - Html5 javascript gettime() from <input type=“date” />,oddly working html5输入类型日期数据列表删除其他选项 - html5 input type date datalist remove other options 如何将 html5 输入类型的日期和时间转换为 javascript datetime - How to convert html5 input type date and time to javascript datetime 如果输入错误,HTML5输入类型日期有时为空值 - HTML5 input type date is sometimes empty value if entered incorrectly
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM