如题,
客户端代码:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" EnableSessionState="True" %><!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>Untitled Page</title>
<script language="javascript" type="text/javascript">
// <!CDATA[function sb_insert_onclick() {  
  var obj = document.getElementById('table1');
  var mRow = obj.insertRow(-1);
  var mCell = mRow.insertCell();
  mCell.colspan ="3";
  mCell.innerHTML="<FONT size=5>Report Online</FONT> ";     
}// ]]>
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div style="text-align: center">
            <table border="0" cellpadding="0" cellspacing="0" id= "table1">
                <tr>
                    <td colspan="3"><input type="submit" id="sb_insert" onclick="sb_insert_onclick()" /><div style="text-align: center">
                            
                        </div>
                    </td>
                </tr>
                <tr><td colspan="3"><asp:TextBox ID="tbx_test" runat="server"></asp:TextBox>
                </td>
                </tr>
            </table>
            <table border="0" cellpadding="0" cellspacing="0" id= "table2">
                                
            </table>
        </div>
    
    </div>
    </form>
</body>
</html>
服务器端代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page 
{      protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!Page.IsPostBack)
        {
            
        }
    }
}
不知道问题出在那里了

解决方案 »

  1.   

    不要用服务器控件。客户端的即可
    <input type=button onclick="sb_insert_onclick()" />
      

  2.   

    因为你提交刷新没了<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddCell.aspx.cs" Inherits="AddCell" %>
    <!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 id="Head1" runat="server">
        <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
    // <!CDATA[function sb_insert_onclick() {  
      var obj = document.getElementById('table1');
      var mRow = obj.insertRow();
      var mCell = mRow.insertCell();
      mCell.colspan ="3";
      mCell.innerHTML="<FONT size=5>Report Online</FONT> ";     
    }// ]]>
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <div style="text-align: center">
                <table border="0" cellpadding="0" cellspacing="0" id= "table1">
                    <tr>
                        <td colspan="3"><input type="submit" id="sb_insert" onclick="sb_insert_onclick()" /><div style="text-align: center">
                                
                            </div>
                        </td>
                    </tr>
                    <tr><td colspan="3"><asp:TextBox ID="tbx_test" runat="server"></asp:TextBox>
                    </td>
                    </tr>
                </table>
                <table border="0" cellpadding="0" cellspacing="0" id= "table2">
                                    
                </table>
            </div>
        
        </div><input type="button" onclick="sb_insert_onclick()" value="add" />    </form>
    </body>
    </html>
      

  3.   

    1. 
    因为你重新提交页面了, 刷新过后自然没有了2.
    使用:
    <input type="button" onclick="sb_insert_onclick()" value="add" />