为什么服务器button要按两次才能复制表格
wnsre 2016-06-06 02:11:26 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="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>
<script type="text/javascript" language="JavaScript">
function CopyTable()
{
var txt = document.body.createTextRange();
var r_type = document.getElementById("Table1"); //表格的ID值
txt.moveToElementText(r_type);
txt.select();//选择对象
document.execCommand("Copy"); //执行浏览器复制命令
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" clientidmode="Static" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Table ID="Table1" runat="server" BorderWidth="1px">
<asp:TableRow ID="TableRow1" runat="server">
<asp:TableCell ID="TableCell1" runat="server">
</asp:TableCell>
<asp:TableCell ID="TableCell2" runat="server">
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</form>
</body>
</html>
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Table1.Rows[0].Cells[0].Text=TextBox1.Text;
Table1.Rows[0].Cells[1].Text =TextBox2.Text;
// Button1.Attributes.Add("onclick", "return CopyTable()");
Button1.Attributes["onclick"] = "return CopyTable()";
}
}
按第一次没反应,每次输入不同的值都要按两次button,为什么?
win7+vs.net2008测试环境