I am developing single page website using asp.net , at bottom of my page I have created contact us form. problem is that when I click on the submit button of contact us form . it automatically goes to top of the page html code is here `
<form id="form1" runat="server">
<div>
<h2>Contact Us</h2>
<br />
<table>
<!-- Name -->
<tr>
<td align="center">
Name:</td>
<td>
<asp:TextBox ID="txtName"
runat="server" BackColor="Transparent"
Columns="50"></asp:TextBox>
</td>
</tr>
<!-- Subject -->
<tr>
<td align="center">
Subject:
</td>
<td>
<asp:TextBox ID="ddlSubject" runat="server"></asp:TextBox>
</td>
</tr>
<!-- Message -->
<tr>
<td align="center">
Message:
</td>
<td>
<asp:TextBox ID="txtMessage"
runat="server"
Columns="40"
Rows="6"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<!-- Submit -->
<tr align="center">
<td colspan="2">
<a href="#btnSubmit">
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" /></a>
</td>
</tr>
<!-- Results -->
<tr align="center">
<td colspan="2">
<asp:Label ID="lblResult" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</form>`
使用UpdatePanel,或者如果您真的要执行SPA,请考虑使用AJAX进行站点开发,并只编写Web服务。
Set this in your Page_Load function:
Page.MaintainScrollPositionOnPostBack = true;
If you wish to return to the same scroll location on the page after the button is clicked.
You need to add MaintainScrollPositionOnPostback="true" to the "<%@ Page" tag, you can also set it in code-behind or web.config:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.