按钮控件无法正常运行

发布于 2025-02-09 13:04:21 字数 3247 浏览 0 评论 0原文

我想提前向问题的标题表示歉意,但我真的不知道我还能问一下。目前,我有一个按钮,而它所做的只是设置一个我必须真实的面板的可见性,但是当我单击按钮时,什么也不会发生。如果我在.aspx文件中将面板的ASP控件上的可见性属性设置为true,则面板将显示,而不是在我单击按钮时。下面我发布了相对于此按钮的代码。

.aspx代码:

<asp:Button ID="btnShowTop5" runat="server" Text="Top 5" CausesValidation="False" OnClick="btnShowTop5_Click" />

page_load事件中,我将面板的可见性设置为false:

pnlTop5.Visible = False

.appx代码,用于所讨论的面板:

<asp:Panel ID="pnlTop5" CssClass="gvTop5Box1" ScrollBars="Auto" runat="server">
    <table>
        <tr>
            <th>
                <div style="width: 100%; height: auto;">
                    Top 5 Order Codes
                </div>
            </th>
        </tr>
        <tr>
            <td>
                <p style="padding: 2px; margin: 2px; width: auto; height: auto; color: cornsilk;">These are you top 5 most used Order Codes.</p>
                <hr style="color: #822402; width: 100%;" />
            </td>
        </tr>
        <tr>
            <td>
                <div style="overflow: auto; width: 100%;">
                    <asp:GridView ID="gvTop5OC" runat="server" Width="99%" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
                        BorderWidth="1px" CellPadding="4" AutoGenerateColumns="False" PageSize="20">
                        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
                        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
                        <RowStyle BackColor="White" ForeColor="#330099" />
                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
                        <SortedAscendingCellStyle BackColor="#FEFCEB" />
                        <SortedAscendingHeaderStyle BackColor="#AF0101" />
                        <SortedDescendingCellStyle BackColor="#F6F0C0" />
                        <SortedDescendingHeaderStyle BackColor="#7E0000" />
                        <Columns>
                            <asp:BoundField DataField="OrderCode" HeaderText="Order Code" SortExpression="OrderCode" Visible="True" ReadOnly="True" />
                            <asp:BoundField DataField="Quantity" HeaderText="Times Used" SortExpression="Quantity" />
                        </Columns>
                    </asp:GridView>
                </div>
            </td>
        </tr>
    </table>
</asp:Panel>

vb code for the Button单击事件事件:

Protected Sub btnShowTop5_Click(sender As Object, e As EventArgs) Handles btnShowTop5.Click
    pnlTop5.Visible = True
End Sub

当按钮单击时站立时,什么都没有发生,我不知所措,这是我第一次看到这种情况,尤其是对于看起来如此简单的事情。对于此问题的任何帮助,都将不胜感激,如果我缺少任何有助于更好地理解问题的信息,请让我知道,我很乐意为此提供。

I would like to apologize in advance for the title of the question but I don't really know how else I could ask it. Currently I have a button, and all it does is set the visibility of a panel I have to true, but when I click on the button nothing happens. If I set the visibility attribute on the asp control for the panel to True in the .aspx file, the panel will show up, just not when I click the button. Below I have posted my code relative to this button.

.aspx code:

<asp:Button ID="btnShowTop5" runat="server" Text="Top 5" CausesValidation="False" OnClick="btnShowTop5_Click" />

In the page_load event I set the visibility of the panel to false:

pnlTop5.Visible = False

.aspx code for the panel in question:

<asp:Panel ID="pnlTop5" CssClass="gvTop5Box1" ScrollBars="Auto" runat="server">
    <table>
        <tr>
            <th>
                <div style="width: 100%; height: auto;">
                    Top 5 Order Codes
                </div>
            </th>
        </tr>
        <tr>
            <td>
                <p style="padding: 2px; margin: 2px; width: auto; height: auto; color: cornsilk;">These are you top 5 most used Order Codes.</p>
                <hr style="color: #822402; width: 100%;" />
            </td>
        </tr>
        <tr>
            <td>
                <div style="overflow: auto; width: 100%;">
                    <asp:GridView ID="gvTop5OC" runat="server" Width="99%" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
                        BorderWidth="1px" CellPadding="4" AutoGenerateColumns="False" PageSize="20">
                        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
                        <PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
                        <RowStyle BackColor="White" ForeColor="#330099" />
                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
                        <SortedAscendingCellStyle BackColor="#FEFCEB" />
                        <SortedAscendingHeaderStyle BackColor="#AF0101" />
                        <SortedDescendingCellStyle BackColor="#F6F0C0" />
                        <SortedDescendingHeaderStyle BackColor="#7E0000" />
                        <Columns>
                            <asp:BoundField DataField="OrderCode" HeaderText="Order Code" SortExpression="OrderCode" Visible="True" ReadOnly="True" />
                            <asp:BoundField DataField="Quantity" HeaderText="Times Used" SortExpression="Quantity" />
                        </Columns>
                    </asp:GridView>
                </div>
            </td>
        </tr>
    </table>
</asp:Panel>

VB code for the button click event:

Protected Sub btnShowTop5_Click(sender As Object, e As EventArgs) Handles btnShowTop5.Click
    pnlTop5.Visible = True
End Sub

As it stands when the button is clicked, nothing happens and I am at a loss as to why, this is the first time I have seen this happen especially for something that seems so simple. Any help with this problem would be greatly appreciated and if I am missing any information that would help better understand the problem please let me know, I would be happy to supply it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倦话 2025-02-16 13:04:21

如果您在pageload事件中放置一个断点,则将面板可见性设置为false,您很可能会在两次(在各种情况下)两次调用Pageload事件,因此可能会两次击中断点。我相信,在按钮处理程序将其设置为真后,可见度就会恢复到错误。考虑在面板上的ASPX页面中设置可见光=“ false”,而不是在代码中设置它。

If you put a breakpoint in your PageLoad event, where you are setting the panel visibility to false you are likely to hit the breakpoint twice as sometimes .NET will call the PageLoad event twice (under various circumstances). I believe the visibility is being set back to false after your button handler has set it to true. Consider setting Visible="False" in the aspx page on the panel rather than setting it in code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文