如何隐藏div直到某个日期

时间:2012-09-17 15:51:22

标签: c# html date

我有一个div需要隐藏到10月12日,然后从10月13日开始显示。该站点是用C#.NET构建的,所以我可以在HTML页面的代码隐藏中添加一个if语句。不确定这是否可行或者我是否需要jQuery解决方案(我对此一无所知)。任何帮助将不胜感激。

以下是HTML中的代码:

<p style="bold">SHOW THROUGH 10/12!!!<p>
<p>Every day from now until Metastatic Breast Cancer Awareness Day (Oct. 13), a new video will be featured. Please check-in every day to hear a new story and come back on Oct. 13 to see the new, complete video wall.</p>

<div id="mbcRadioList">
    <p style="bold">BUILD BUT HIDE UNTIL 10/13!!!<p>
    <p><strong>Want to learn more?</strong> Select a video topic to better understand the varied experiences of people living with MBC and their family and friends.</p>
    <div class="checkBoxesColumn">
        <label><input name="videoWallRadio" type="radio" id="" value="" />View All</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" checked />My MBC Journey</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Challenges</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Positive Outlooks &amp; Advice</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Giving Thanks</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Family / Friend Perspective</label>
    </div>
</div>

我在列表周围添加了<div id="mbcRadioList">,以获得控制代码隐藏的句柄,如果有办法的话。如果它是一个jQuery解决方案,我可以删除它。

提前致谢!

1 个答案:

答案 0 :(得分:3)

按照对方的建议行事:

1)将div设置为runat="server"

2)将div设置为visible="false"

3)在Page_Load中,在您的代码隐藏中,添加if语句,检查日期,然后将visible更改为true

aspx标记:

<div id="mbcRadioList" runat="server" visible="false">
    <p style="bold">BUILD BUT HIDE UNTIL 10/13!!!<p>
    <p><strong>Want to learn more?</strong> Select a video topic to better understand the varied experiences of people living with MBC and their family and friends.</p>
    <div class="checkBoxesColumn">
        <label><input name="videoWallRadio" type="radio" id="" value="" />View All</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" checked />My MBC Journey</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Challenges</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Positive Outlooks &amp; Advice</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Giving Thanks</label>
        <label><input name="videoWallRadio" type="radio" id="" value="" />Family / Friend Perspective</label>
    </div>
</div>

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
    {
        // ..... your other code

                    if(DateTime.Now >= new DateTime(2012, 10, 13) ){
                          mbcRadioList.Visible = true;
                    }
    }

正如其他人所建议的那样,如果需要,请务必考虑时区。