0

在此处输入图像描述

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

我是 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;
        }
4

2 回答 2

0

按照 Garrison Neely 的建议进行操作,然后对于您不想验证的那些文本框,将“CausesValidation”属性设置为“False”。

于 2013-07-24T23:25:38.030 回答
0

最快的解决方案是将所有内容包装在<asp:UpdatePanel>

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

它将为您阻止页面闪烁。

于 2013-07-24T22:13:13.040 回答