本文介绍了将值设置为输入类型=“日期".从代码背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ASP.NET Web应用程序中C#代码背后的HTML标记input type="date"中分配值.页面加载后,该值不可见,但是在chrome dev工具中,我可以看到该值:

I want to assign value to my HTML tag input type="date" from C# codebehind in ASP.NET web application. After page is loaded, the value is not visible, but in chrome dev tools i can see the value:

ASPX:

<input type="date" runat="server" id="date_datumPrispetja" value="dd. MM. yyyy" />

隐藏代码:

string date = myDate.ToString("dd. MM. yyyy"); //value of date: "09. 04. 2017";
date_datumPrispetja.Value = date;

甚至有可能将代码背后的值分配给此HTML5元素吗?

Is this is even possible, to assign value from codebehind to this HTML5 element?

比较datetimedate输入类型. C#:

date_datumPrispetja.Value = DateTime.Now.ToString("dd. MM. yyyy");
hi.Value = DateTime.Now.ToString("dd. MM. yyyy");

ASPX:

<input type="date"  runat="server" id="date_datumPrispetja" value="dd. MM. yyyy"/>
<br />
<input type="datetime" runat="server" id="hi" value="dd. MM. yyyy" />

结果:

推荐答案

我认为应该可行,您将此代码放在哪里?

I think it should be work, where did you put this code in:

string date = myDate.ToString("dd. MM. yyyy"); //value of date: "09. 04. 2017";
date_datumPrispetja.Value = date;

Page_Load()?

Page_Load()?

我的测试代码如下:

protected void Page_Load(object sender, EventArgs e)
    {
        hi.Value = DateTime.Now.ToString("yyyy-MM-dd");
    }

然后效果很好.

这篇关于将值设置为输入类型=“日期".从代码背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 04:18