admin管理员组文章数量:1399466
I have a textbox with the property type="date"
. I am able to retrieve the value in backcode but when I try to assign a value, the placeholder "mm/dd/yyyy"
is shown.
When I view the markup, the expected value is there - "value='01/01/1991'"
. I think it has to do with JavaScript overriding the value.
Any suggestion on how I can work around this?
Edit: Sorry, forgot to include the markup and code
So my markup is
<asp:TextBox ID="txtBirthdate" runat="server" class="form-control input-sm" type="date" onkeypress="handleEnter(event)" />
and c# is
txtBirthdate.Text = usr.BirthDate.ToString("MM/dd/yyyy");
the resulting markup is
<input name="ctl00$ctl00$ctl00$ctl00$Body$Body$Body$Body$txtBirthdate" value="01/20/1991" id="ctl00_ctl00_ctl00_ctl00_Body_Body_Body_Body_txtBirthdate" class="form-control input-sm" type="date" onkeypress="handleEnter(event)">
So as you can see, the value was assigned.
I have a textbox with the property type="date"
. I am able to retrieve the value in backcode but when I try to assign a value, the placeholder "mm/dd/yyyy"
is shown.
When I view the markup, the expected value is there - "value='01/01/1991'"
. I think it has to do with JavaScript overriding the value.
Any suggestion on how I can work around this?
Edit: Sorry, forgot to include the markup and code
So my markup is
<asp:TextBox ID="txtBirthdate" runat="server" class="form-control input-sm" type="date" onkeypress="handleEnter(event)" />
and c# is
txtBirthdate.Text = usr.BirthDate.ToString("MM/dd/yyyy");
the resulting markup is
<input name="ctl00$ctl00$ctl00$ctl00$Body$Body$Body$Body$txtBirthdate" value="01/20/1991" id="ctl00_ctl00_ctl00_ctl00_Body_Body_Body_Body_txtBirthdate" class="form-control input-sm" type="date" onkeypress="handleEnter(event)">
So as you can see, the value was assigned.
Share Improve this question edited May 8, 2014 at 14:33 Comfortably Numb 39.8k17 gold badges80 silver badges145 bronze badges asked May 8, 2014 at 7:41 LiaooLiaoo 4256 silver badges21 bronze badges 2- show some .aspx and .cs what u tried – Dgan Commented May 8, 2014 at 7:42
- please share some html code or JSFiddle will be better – Bhushan Kawadkar Commented May 8, 2014 at 7:53
2 Answers
Reset to default 4I believe this only happens in Chrome. It requires value assignment to be in "yyyy-MM-dd" format. Try in your C#
txtBirthdate.Text = usr.BirthDate.ToString("yyyy-MM-dd");
This should display the correct value (and it doesn't affect the format of the display).
If will display in this format in other browsers tho. You may want to do some browser detection, e.g.
if (Request.Browser.Browser == "Chrome")
{
txtBirthdate.Text = usr.BirthDate.ToString("yyyy-MM-dd");
} else {
txtBirthdate.Text = usr.BirthDate.ToString("MM/dd/yyyy");
}
but perhaps something more sophisticated
For me this worked:
txtBirthdate.Text = Convert.ToDateTime(TablaHabitacion.Rows[fila].Cells[6].Text).ToString("yyyy-MM-dd");
本文标签: javascripthow to show value of textbox typedate aspnetStack Overflow
版权声明:本文标题:javascript - how to show value of textbox type=date asp.net - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744127058a2592002.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论