如何在ASP.NET中基于页面加载事件中的两个日期显示或隐藏文本框。

huangapple go评论104阅读模式
英文:

How to show or hide a textbox in asp.net based on two dates in page load event

问题

如果日期选择器的选定值小于标签上的日期值,在页面加载时,我想显示文本框,否则隐藏它。我该如何做到这一点?

英文:

I have a webform with label,2 datepicker and a textbox.I have a date value in label.On page load if datepicker selected value is less than label value,i want to show textbox,else hide it.How can i do this?

答案1

得分: 1

首先将文本框的 visible 属性设置为 false,然后执行以下步骤。

var dateFromLabel = label.text;
var dateFromPicker = DateTime.Now;

现在,将从日期选择器中获取的字符串转换为 DateTime 格式。

DateTime dateFromLabelConverted = Convert.ToDateTime(dateFromLabel);
if (dateFromPicker < dateFromLabelConverted)
{
    textbox.visible = true;
}

注意: 如果日期格式不匹配,可能不会给您正确的结果。

英文:

At first set your textbox visible properties to false and do following.

var dateFromLabel = lablel.text; 
var dateFromPicker = DateTime.Now;

Now, Convert this string to DateTime format which you get from datepicker i.e.

DateTime dateFromLabelConverted = Convert.ToDateTime(dateFromLabel);
if (dateFromPicker &lt; dateFromLabelConverted )
{
textbox.visible = true;
}

Note: if date format does not matche it may not gives you proper result.

huangapple
  • 本文由 发表于 2020年1月3日 14:56:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/59574384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定