读书人

服务器控件解析为html控件后onclick

发布时间: 2011-12-31 23:50:30 作者: rapoo

服务器控件解析为html控件后,onclick事件调用js函数居然会刷新页面。
<%@ Page Language= "C# " AutoEventWireup= "true " CodeBehind= "Default.aspx.cs " Inherits= "_Default " %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 无标题页 </title>
<style type= "text/css ">
#EmployeeSort {
width:100px;
}
#EmployeeBox {
float:left;
}

#EmployeeOperate {
float:right;
vertical-align: middle;
}
</style>
<script language= "JavaScript " type= "text/javascript ">
//listbox中item项交换位置
function changepos(obj,index)
{
if(index == -1)
{
if (obj.selectedIndex > 0)
{
obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex-1))

}
}
else if(index == 1)
{
if (obj.selectedIndex <obj.options.length-1)
{
obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex+1))
}
}
var t = obj.selectedIndex;
if (t == -1)
{


return;
}
obj.focus();
obj.selectedIndex = t;
}
</script>
</head>
<body>
<form id= "form1 " runat= "server ">
<div id= "EmployeeSort ">
<div id= "EmployeeBox ">
<asp:ListBox ID= "ListBoxEmployee " runat= "server " Height= "250px " AutoPostBack= "True "> </asp:ListBox>
</div>
<div id= "EmployeeOperate ">
<p> <input type= "image " id= "UpSort " onclick= "changepos(ListBoxEmployee,-1) "/> </p>
<p> <input type= "image " id= "DownSort " onclick= "changepos(ListBoxEmployee,1) "/> </p>
</div>
</div>
</form>
</body>
</html>

[解决办法]
把input按钮放到form外面去

读书人网 >asp.net

热点推荐