我如何在ontick事件中启用div代码?

时间:2015-04-22 03:31:40

标签: c# asp.net

.aspx页面      

   <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>

    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
     <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" >
    </asp:Timer>
    <br />
    <br />
    <table style="position: absolute; top: 600px; left: 167px; width: 1010px; height: 124px;">
    <tr>
     <td><asp:Label ID="Label13" runat="server"></asp:Label></td>
        <td >DAYS</td>
     <td><asp:Label ID="Label14" runat="server"></asp:Label></div></td>
        <td > HOURS</td>
     <td><asp:Label ID="Label15" runat="server"></asp:Label></td>
         <td >MIN</td>
     <td><asp:Label ID="Label16" runat="server"></asp:Label></td>
        <td >  SEC</td>
     <td><asp:Label ID="Label17" Text="=Remaining For Vote Day" runat="server"  ></asp:Label></td>
    </tr>
    </table>   

         </ContentTemplate>
     </asp:UpdatePanel>
     </div>

   <div id="theDiv1" runat="server" style="height: 182px;display:none">
        <table align="center" class="auto-style1" style="border-style: dashed; border-color: #008000; height: 179px; width: 366px; margin-left: 300px;">
              <tr>
                  <td class="auto-style2">&nbsp;</td>
                  <td>
                       <asp:Label ID="Label1" runat="server" Font-Bold="true" Font-Size="X-Large" Text="Voter login"></asp:Label>
                  </td>
              </tr>
              <tr>
                  <td class="auto-style2">
                        <asp:Label ID="Label2" runat="server" Text="Name"> </asp:Label>
                  </td>
                  <td>
                        <asp:TextBox ID="TextBox1" runat="server" Width="177px"></asp:TextBox>
                  </td>
              </tr>
              <tr>
                   <td class="auto-style2">
                        <asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>
                   </td>
                   <td>
                        <asp:TextBox ID="TextBox2" runat="server" TextMode="Password" Width="179px"></asp:TextBox>
                   </td>
               </tr>
               <tr>
                   <td class="auto-style2">&nbsp;</td>
                   <td>
                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Log in" Width="65px" />
                        <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">New User</asp:LinkButton>
                   </td>
               </tr>
               <tr>
                   <td class="auto-style2">&nbsp;</td>
                   <td>
                       <asp:LinkButton ID="LinkButton2" runat="server" OnClick="LinkButton2_Click">Forgot Password</asp:LinkButton>
                   </td>
               </tr>
        </table>
        <asp:Label ID="label4" runat="server"></asp:Label>
  </div>

</Content>

.aspx.cs页面

    protected void Timer1_Tick(object sender, EventArgs e)
    {

        DateTime dt = DateTime.Now;
        TimeSpan differ;
        System.DateTime date1 = new System.DateTime(2015, 4, 1, 20, 10, 0);
        differ = date1.Subtract(dt);
        double t = differ.TotalSeconds;

        if (t > 0)
        {
            double dy, h, m, s;
            dy = differ.Days;
            h = differ.Hours;
            m = differ.Minutes;
            s = differ.Seconds;
            Label13.Text = dy.ToString();// +" Days " + h + " Hours " + m + " Minutes " + s + " Seconds left for celebration";
            Label14.Text = h.ToString();
            Label15.Text = m.ToString();
            Label16.Text = s.ToString();
        }
        else
        {
            Timer1.Enabled = false;

            time_enable.Visible = false;

           theDiv1.Visible = true;

        }
    }

撰写theDiv1.Visible = true;后,此声明theDiv1不可见且不起作用。

我该如何解决?

1 个答案:

答案 0 :(得分:0)

您已在样式属性中设置display=none并在服务器端设置Visible=true这是没有意义的!!所以你需要按照下面这样做

theDiv1.Style.Remove("display");//To be on safer side do this first
theDiv1.Style.Add("display","block"); 

theDiv1.Style.Add(HtmlTextWriterStyle.Display, "block");

<强>替代

如果您对div进行了如下更改

<div id="theDiv1" Visible="false" runat="server" style="height: 182px;">

然后你写的任何代码肯定会有用。