当单选按钮选择更改不会导致刷新?

发布于 2024-08-30 19:34:17 字数 769 浏览 1 评论 0原文

当单选按钮的选择发生变化时,我想在下一个表格单元格中显示/隐藏面板。我将其隐藏和显示得很好,但每次都会导致页面刷新到顶部。他们是阻止刷新的方法吗?我想动态隐藏和显示面板。

<table>
<tr>
            <td>
                <asp:RadioButtonList runat="server" ID="rblPlayerStatus" AutoPostBack="true" >
                    <asp:ListItem>Free Agent</asp:ListItem>
                    <asp:ListItem>I have teammate</asp:ListItem>
                </asp:RadioButtonList>
            </td>
            <td>
                <asp:Panel runat="server" ID="pnlTeamMate">
                    <asp:Label runat="server" ID="lblTeamMate" Text="Choose Teammate" />
                </asp:Panel>
            </td>
        </tr>      
</table>

When the selection of the radio buttons change I would like to show/hide the panel in the next table cell. I have it hiding and showing fine but each time it causes the page to refresh to the top. Is their a way to stop that refresh? I would like to hide and show the panel dynamically.

<table>
<tr>
            <td>
                <asp:RadioButtonList runat="server" ID="rblPlayerStatus" AutoPostBack="true" >
                    <asp:ListItem>Free Agent</asp:ListItem>
                    <asp:ListItem>I have teammate</asp:ListItem>
                </asp:RadioButtonList>
            </td>
            <td>
                <asp:Panel runat="server" ID="pnlTeamMate">
                    <asp:Label runat="server" ID="lblTeamMate" Text="Choose Teammate" />
                </asp:Panel>
            </td>
        </tr>      
</table>

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

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

发布评论

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

评论(4

鲸落 2024-09-06 19:34:17

使用 AJAX.ASP.Net 库 - 然后添加 ScriptManager 项和 UpdatePanel。 UpdatePanel 中的任何内容都将通过 AJAX 进行更新,而不是整个页面刷新。

Use the AJAX.ASP.Net library - then you add a ScriptManager item, and an UpdatePanel. Anything within the UpdatePanel will update through AJAX, not a full page refresh.

感受沵的脚步 2024-09-06 19:34:17

您是否有基于显示和隐藏面板的服务器端逻辑。如果是,那么您可以使用更新面板控件。如果只是客户端逻辑,例如

如果选择 Free Agent,则选择显示 FreeAgent 面板,否则团队面板

使用 javascript 或 jquery 来实现相同的效果。

Do you have any server side logic based on which show and hide the panel. If yes then you could use update panel control. If it is just client side logic such as

If Free Agent is select show FreeAgent Panel else Team Panel

use javascript or rather jquery to achieve the same.

作死小能手 2024-09-06 19:34:17

从您的代码中,我看不到您隐藏和显示面板的位置。您可以使用更新面板,但最好在需要从服务器检索更多信息时使用。

如果您只想显示和隐藏面板,则可以使用 Javascript 做得更好,方法是向 OnClick 事件添加一些代码来设置面板的可见性 css 属性。谷歌上有一些关于如何做到这一点的教程。像这个 应该足以帮助您入门。

From your code, I can't see where you hide and show the panel. You could use an updatepanel, but that is best used when you need to retrieve more information from the server.

If you simply want to show and hide the panel, you can do it better with Javascript, by adding some code to the OnClick event to set the panel's visibility css attribute. There are a few tutorials on google about how to do this. Something like this should be sufficient to get you started.

[旋木] 2024-09-06 19:34:17

解决方案是使用 AJAX(UpdatePanel 和 ScriptManager)或删除
AutoPostback = true 并使用 JavaScript 显示/隐藏面板

Solution would be either using AJAX (UpdatePanel and ScriptManager) or removing
AutoPostback = true and using JavaScript to display/hide the panel

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