【问题标题】:ASP.NET Stop re-load whole page when click a button?ASP.NET 单击按钮时停止重新加载整个页面?
【发布时间】:2013-07-24 21:42:36
【问题描述】:

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

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

【问题讨论】:

标签: asp.net calendar


【解决方案1】:

最快的解决方案是将所有内容包装在 &lt;asp:UpdatePanel&gt; 中:

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

它会为你阻止页面闪烁。

【讨论】:

  • 我将所有这些文本框、按钮和日历都放在了 UpdatePanel 中,现在当我单击一个按钮时什么也没发生?
  • 好的,我发现它只有在其他文本框(我在表单中有几个文本框,所有需要填写的文本框)都已完成时才有效,换句话说,所有其他有效控件都应该有效。如何让它忽略其他控件?
  • 关闭 CausesValidation
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 2013-04-28
    • 2021-03-01
    • 2016-02-01
    • 1970-01-01
    • 2016-11-07
    • 1970-01-01
    相关资源
    最近更新 更多