从用户控件将 asp.net 页面刷新到页面顶部

发布于 2024-08-13 09:54:54 字数 831 浏览 1 评论 0原文

我正在使用一个表单的更新面板,当单击“继续”按钮时,该面板会返回到同一页面,但会显示要填写的不同字段。其中一个字段是一些信用卡数据,是用户控件的一部分。用户控件有一个“立即付款”按钮。因此,页面内有一个用户控件,其中包含您填写的字段,然后单击“立即付款”。点击此按钮后,如果出现验证错误,错误会显示在页面顶部,但页面不会移动到页面顶部。我想知道用户单击包含在更新面板中的页面上的用户控制按钮后如何滚动到页面顶部。(在这种情况下,最好使用 javascript 而不是 jquery)

代码示例:

<ajax:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
       <asp:ImageButton ID="ContinueButton" runat="server" AlternateText="Continue"  SkinID="Continue" EnableViewState="false" OnClick="ContinueButton_Click" ValidationGroup="group1" />
</ContentTemplate>
</ajax:UpdatePanel>

在代码隐藏中,用户控件被实例化。

ASP.CreditCardStuff cc = new ASP.CreditCardStuff();
                cc.ValidationGroup = "group1";
                phForms.Controls.Add(cc);

这是包含“立即付款”按钮的用户控件

I am using an update panel for a form that when continue button is clicked returns to the same page but makes visible different fields to be filled in. One of the fields is some credit card data and is part of a user control. The user control has a "Pay Now" button. So, inside the page there is a user control containing fields that you fill in and then click "Pay Now". After hitting this button, if there's a validation error, error shows at the top of the page but the page doesn't move to top of page. I would like to know how after the user clicks on the user control button that is on a page that is wrapped in update panel can I scroll to the top of the page.(javascript not jquery would be preferable in this instance)

Code samples:

<ajax:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
       <asp:ImageButton ID="ContinueButton" runat="server" AlternateText="Continue"  SkinID="Continue" EnableViewState="false" OnClick="ContinueButton_Click" ValidationGroup="group1" />
</ContentTemplate>
</ajax:UpdatePanel>

In Code behind a user control is instantiated.

ASP.CreditCardStuff cc = new ASP.CreditCardStuff();
                cc.ValidationGroup = "group1";
                phForms.Controls.Add(cc);

This is the user control that contains the "Pay Now" button

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

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

发布评论

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

评论(2

灯下孤影 2024-08-20 09:54:54

在按钮旁边和页面顶部提供验证错误指示器怎么样?这样,页面将保持滚动到同一点(对用户来说更好),而不是跳到顶部,纯粹是为了使页面顶部的错误指示器可见(不太好)。

How about providing a validation error indicator next to the button as well as at the top of the page? This way the page would remain scrolled to the same point (nicer for the user), rather than jumping to the top, purely to make the error indicator at the top of the page visible (not so nice).

浅紫色的梦幻 2024-08-20 09:54:54

您可以处理 end_request 事件:

function pageLoad(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (sender, args) {
        if (args.get_error() == null) {
            // do the scrolling here
        }
    });
}

You could handle the end_request event:

function pageLoad(sender, args) {
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (sender, args) {
        if (args.get_error() == null) {
            // do the scrolling here
        }
    });
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文