ASP.NET:使用AutoPostBack时如何阻止页面跳转?

发布于 2024-10-08 07:14:09 字数 248 浏览 7 评论 0原文

我正在使用 ASP.NET,在向导控件中,我有单选按钮,如果选择“是”,则显示一个面板,但如果选择“否”,则隐藏该面板。我已将 MaintenanceScrollPositionOnPostBack 设置为 True,但 ActiveStepChanged 事件将其更改为 False,以便当您单击“下一步”查看下一个向导步骤时,它将从页面顶部开始。问题是,单击“下一步”后,第一次单击单选按钮时,它会跳转到页面顶部(第一次单击单选按钮后,页面会保留其位置)。如何阻止它第一次跳跃?

I'm using ASP.NET, and in a Wizard control I have radio buttons where if "Yes" is selected, a panel is shown, but if "No" is selected, the panel is hidden. I have MaintainScrollPositionOnPostBack set to True, though the ActiveStepChanged event changes it to False so that when you click Next to see the next Wizard step, it will start at the top of the page. The problem is, after clicking Next, the first time you click on a radio button it jumps to the top of the page (the page retains its position any time you click a radio button after the first time). How do I stop it from jumping the first time?

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

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

发布评论

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

评论(3

不羁少年 2024-10-15 07:14:09

设置 Page.MaintainScrollPositionOnPostBack = true 以在回发时保持当前屏幕位置。

这比尝试通过 JavaScript 或其他方式自己完成此操作更容易。

Set Page.MaintainScrollPositionOnPostBack = true to maintain the current screen position on Postback.

This is easier than trying to do this yourself through JavaScript or whatever means.

夏尔 2024-10-15 07:14:09

您可以通过将控件放入 更新面板

You can stop the page from doing a full refresh by putting your control in an UpdatePanel

ˉ厌 2024-10-15 07:14:09

我知道这个问题已经得到解答,但我无法在我正在从事的项目中使用 ajax 我遇到了类似的问题,并且我找到了一个可接受的解决方法。我在一个页面中有一个用户控件,该页面也有一个母版页。在用户控件中有一个输入表单,在底部附近有一些触发回发的控件。母版页上的主要内容 div 使其可滚动(因为它太大)。我找到的解决方案是将页面焦点设置为由 C# 代码隐藏中的回发触发的事件的控件。
例如:

protected void cbShip_CheckedChanged(object sender, EventArgs e)    
{
    if (cbShip.Checked)
    {
        pnlShip.Visible = true;
        Page.SetFocus(ddlShipCountry);
    }
    else
    {
        pnlShip.Visible = false;
    }
    return;
}

I know this has been answered, but I am unable to use ajax for the project I was working on I was having a similar issue and I found an acceptable work-around. I have a user control within a page that also has a master page. In the user control there is an input form that has a few controls near the bottom that trigger postback. The main content div on the master page makes this for scrollable (because it is too large). The solution that I found to it was setting the page focus to a control on the events triggered by postback in the c# code-behind.
For example:

protected void cbShip_CheckedChanged(object sender, EventArgs e)    
{
    if (cbShip.Checked)
    {
        pnlShip.Visible = true;
        Page.SetFocus(ddlShipCountry);
    }
    else
    {
        pnlShip.Visible = false;
    }
    return;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文