1
<asp:Panel ID="Panel5" runat="server" >
</asp:Panel>

    <asp:Panel ID="Panel6" runat="server" >
</asp:Panel>

<asp:Panel ID="Panel7" runat="server" >
</asp:Panel>

<asp:Button runat="server" ID="addButton" Text="Add More"  OnClick="btnMore_click" AutoPostBack ="false" style="margin-left: 877px" Width="84px"/>

如上面的代码,每个按钮单击我有三个 asp 面板,通过 btnMore_click 函数可见一个面板。

 protected void btnMore_click(object sender, EventArgs e)
    {
        int count = this.Controls;

        if(count == 1)
        {
            medPanel5.Visible = true;
            this.Controls++;
        }
        if (count == 2)
        {
            medPanel6.Visible = true;
            this.Controls++;
        }
        if (count == 3)
        {
            medPanel7.Visible = true;
            this.Controls++;
        }
    }

但目前,当我单击按钮一组可见 true 时。我没有任何问题。但我面临页面重新加载,每次我需要向下滚动以单击添加更多按钮。有没有办法在这里停止页面重新加载?

4

1 回答 1

1

这是服务器端按钮。如果您在服务器端有任何处理而不是页面将回发,请单击此按钮。如果您不想回发页面,请使用 Ajax。

您也可以使用使用更新面板或回调。

于 2021-06-20T04:38:24.510 回答