因此,当我单击“选择”按钮时,将显示日历,我可以选择日期,然后在选择日期后消失。问题是每次我点击按钮都会重新加载整个页面,有什么方法可以阻止它吗?
我是ASP.NET的新手吗?以下是事件的设计代码和实际代码:
<tr>
<td>
Expired Date
</td>
<td>
<asp:TextBox ID="txtExpDate" runat="server"></asp:TextBox>
<asp:Button ID="btnSelectDate" runat="server" OnClick="btnSelectDate_Click" Text="Select" />
<asp:Button ID="btnClearDate" runat="server" OnClick="btnClearDate_Click" Text="Clear" />
</td><td></td>
</tr>
<tr>
<td>
</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>
</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 :(得分:0)
最快的解决方案是将所有内容包装在<asp:UpdatePanel>
:
<asp:UpdatePanel>
<ContentTemplate>
your content, buttons, html, etc
</ContentTemplate
</asp:UpdatePanel>
它会阻止页面闪烁。
答案 1 :(得分:0)
按照Garrison Neely的建议,然后对于那些你不想验证的文本框,将'CausesValidation'属性设置为'False'。