asp.net中的html标签input 点击回车后自动刷新页面是怎么回事??
页面有一个按钮和一个input我将input的onkeydown设置为按钮的click事件,但是执行完按钮的click事件后又自动刷新页面这是怎么回事???...
页面有一个 按钮和一个input 我将input的onkeydown设置为按钮的click事件,但是执行完按钮的click事件后又自动刷新页面 这是怎么回事???
展开
展开全部
asp.net中点击button使得页面不刷新的方法:
控制页面回传:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
//Use ClientClick event to check stop this postback or not.
function onClientClickEvent() {
var text = document.getElementById('textDisplay');
var checkbox = document.getElementById('chkStopPostback');
text.value = "This is a client click";
if (checkbox.checked == true) {
return false;
}
else {
return true;
}
}
</script>
<style type="text/css">
.style1
{
width: 105px;
}
#textDisplay
{
width: 271px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Stop postback:"></asp:Label>
</td>
<td>
<input id="chkStopPostback" type="checkbox" />Is stop?</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Cause postback:"></asp:Label>
</td>
<td>
<asp:Button ID="btnCausePostback" runat="server" Text="Click me to get info"
OnClientClick="return onClientClickEvent()" onclick="btnCausePostback_Click" />
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Postback result:"></asp:Label>
</td>
<td>
<input id="textDisplay" readonly="readonly" type="text" runat="server" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
控制页面回传:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
//Use ClientClick event to check stop this postback or not.
function onClientClickEvent() {
var text = document.getElementById('textDisplay');
var checkbox = document.getElementById('chkStopPostback');
text.value = "This is a client click";
if (checkbox.checked == true) {
return false;
}
else {
return true;
}
}
</script>
<style type="text/css">
.style1
{
width: 105px;
}
#textDisplay
{
width: 271px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td class="style1">
<asp:Label ID="Label1" runat="server" Text="Stop postback:"></asp:Label>
</td>
<td>
<input id="chkStopPostback" type="checkbox" />Is stop?</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label2" runat="server" Text="Cause postback:"></asp:Label>
</td>
<td>
<asp:Button ID="btnCausePostback" runat="server" Text="Click me to get info"
OnClientClick="return onClientClickEvent()" onclick="btnCausePostback_Click" />
</td>
</tr>
<tr>
<td class="style1">
<asp:Label ID="Label3" runat="server" Text="Postback result:"></asp:Label>
</td>
<td>
<input id="textDisplay" readonly="readonly" type="text" runat="server" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询