我的问题是,当我单击带有 id="cmdAddATM"的按钮时,整个 .aspx 页面重新加载。即使我没有编写任何与之关联的单击函数。问题是什么?因为这个问题在我的项目中引起了一些与 ajax/jquery 相关的新问题
文件名:AddEditATM.aspx.cs
namespace Monitoring_Tool
{
public partial class AddEditATM : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Generix.fillDropDown(ref litRegion, Generix.getData("dbo.Region", "REGION, Code", "", "", "Code", 1));
}
}
}
文件:AddEditATM.aspx
<script language="javascript" type="text/javascript">
$(document).ready(function() {
showAddEditATMLoad();
});
</script>
<body>
// I an not writing full syntax here but i have one button with id "cmdAddATM"
</body>
外部 JS 文件:
function showAddEditATMLoad() {
//Its Blank
}
我的 HTML 代码:-
<table style="margin: 0px auto; width: 90%" runat="server">
<thead>
<tr>
<th colspan="4" align="center" class="ui-widget-header PageHeader">
ADD/EDIT ATM
</th>
</tr>
</thead>
<tbody style="vertical-align: bottom; border-style: solid; border-width: thick;">
<tr>
<td style="padding-left: 5px" colspan="2">
Enter ATM ID <input id="txtEditATM" name="txtEditATM" type="text" />
<button id="cmdEditATM">
EDIT ATM</button>
</td>
<td align="left" style="font-weight: bold" colspan="1">
OR
</td>
<td align="center" colspan="2">
<button id="cmdAddATM">
ADD ATM</button>
</td>
</tr>
</tbody>
</table>
最佳答案
如果您的按钮是 <asp:Button runat="server" />
这将呈现为 <input type="submit" />
在浏览器上。因此,它将回发您的页面。
已编辑:添加type="button"
属性为 <button>
标签,
<button>
的类型属性标签具有三个值,在您的情况下标签获取的默认值为提交,这就是它提交您的表单的原因。
1. Submit - For Submitting a Form
2. Reset - For Resetting the Form
3. button - A Simple Button
关于javascript页面加载发生在按钮单击时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12173204/