从用户控件将 asp.net 页面刷新到页面顶部
我正在使用一个表单的更新面板,当单击“继续”按钮时,该面板会返回到同一页面,但会显示要填写的不同字段。其中一个字段是一些信用卡数据,是用户控件的一部分。用户控件有一个“立即付款”按钮。因此,页面内有一个用户控件,其中包含您填写的字段,然后单击“立即付款”。点击此按钮后,如果出现验证错误,错误会显示在页面顶部,但页面不会移动到页面顶部。我想知道用户单击包含在更新面板中的页面上的用户控制按钮后如何滚动到页面顶部。(在这种情况下,最好使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在按钮旁边和页面顶部提供验证错误指示器怎么样?这样,页面将保持滚动到同一点(对用户来说更好),而不是跳到顶部,纯粹是为了使页面顶部的错误指示器可见(不太好)。
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).
您可以处理 end_request 事件:
You could handle the end_request event: