2013-07-24 189 views
0

enter image description hereASP.NET停止单击按钮时重新加载整个页面?

所以,当我点击选择按钮,日历将出现,我可以选择一个日期,然后在我选择日期后消失。问题是,每次我点击按钮整个页面被重新加载,有没有什么办法来防止它?

我是ASP.NET新手?下面是设计代码和事件的实际代码:

 <tr> 
<td> 
    Expired Date 
</td> 
      <td> 

       <asp:TextBox ID="txtExpDate" runat="server"></asp:TextBox> 

&nbsp;<asp:Button ID="btnSelectDate" runat="server" OnClick="btnSelectDate_Click" Text="Select" /> 
&nbsp;<asp:Button ID="btnClearDate" runat="server" OnClick="btnClearDate_Click" Text="Clear" /> 
      </td><td></td> 

     </tr> 
     <tr> 
<td> 
    &nbsp;</td> 
      <td> 
       <asp:Calendar ID="calExpiredDate" runat="server" BackColor="White" BorderColor="#3366CC" BorderWidth="1px" CellPadding="1" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="#003399" Height="200px" Visible="False" Width="220px" OnSelectionChanged="calExpiredDate_SelectionChanged"> 
        <DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" /> 
        <NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" /> 
        <OtherMonthDayStyle ForeColor="#999999" /> 
        <SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" /> 
        <SelectorStyle BackColor="#99CCCC" ForeColor="#336666" /> 
        <TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px" Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" /> 
        <TodayDayStyle BackColor="#99CCCC" ForeColor="White" /> 
        <WeekendDayStyle BackColor="#CCCCFF" /> 
       </asp:Calendar> 
       <br /> 
      </td><td> 
       &nbsp;</td> 
     </tr> 

protected void btnSelectDate_Click(object sender, EventArgs e) 
     { 
      if (calExpiredDate.Visible == false) calExpiredDate.Visible = true; 
      else calExpiredDate.Visible = false; 
     } 

     protected void btnClearDate_Click(object sender, EventArgs e) 
     { 
      txtExpDate.Text = null; 
     } 


     protected void calExpiredDate_SelectionChanged(object sender, EventArgs e) 
     { 
      txtExpDate.Text = calExpiredDate.SelectedDate.ToShortDateString(); 
      calExpiredDate.Visible = false; 
     } 
+0

可以使用['ASP.NET-Ajax'](http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/Calendar/Calendar.aspx)或jQuery。 –

回答

0

最快的解决办法是在<asp:UpdatePanel>包一切:

<asp:UpdatePanel> 
    <ContentTemplate> 
     your content, buttons, html, etc 
    </ContentTemplate 
</asp:UpdatePanel> 

这将阻止该页面闪烁您。

+0

我把所有的这些文本框,按钮和日历在UpdatePanel里面,现在当我点击一个按钮时什么都没有发生? –

+0

好的我发现它只有在其他文本框(我在表单中有几个文本框,所有需要填写的文本框)都已满足时才起作用,换句话说,所有其他有效控件应该都是有效的。如何让它忽略其他控制? –

+0

关闭原因验证 –

0

如Neigh建议的那样做,然后对那些你不想验证的文本框,设置'CausesValidation'属性为'False'。

相关问题