谁帮我看看这个简单的例子问题出在哪了?

来源:百度知道 编辑:UC知道 时间:2024/06/03 03:11:46
在VS2008下编一小段东西.

页面test.aspx中的代码如下插入一个表格一个按钮和一个文本
<body>
<form id="form1" runat="server">
<div>
<table id="table1" width="100%" border="1">
<tr id="row1" runat="server" onclick="Text1.value=(this.id)">
<td>
第一行</td>
</tr>
<tr id="row2" runat="server" onclick="Text1.value=(this.id)">
<td>
第二行</td>
</tr>
</table>
</div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<input id="Text1" type="text" /></form>
</body>

然后在类文件test.aspx.cs中插入如下代码,为实现在页面上单击某一行后

你把Javascript和asp.net后台代码弄混了。
</script>

<body>
<form id="form1" runat="server">
<div>
<table id="table1" width="100%" border="1" runat="server">
<tr id="row1" onclick="b1_onclick('row1')" >
<td>
第一行</td>
</tr>
<tr id="row2" onclick="b1_onclick('row2')">
<td>
第二行</td>
</tr>
</table>
</div>
<input type="button" id="b1" value="Button" onclick="return b1_onclick('row1')" />
<input id="Text1" type="text" runat="server"/></form>
</body>

再看看,不知道是不是你要的效果。。把你的CS代码全部删掉。。至于你的CS代码为什么不能编译通过, 是因为Text1和 table1没有声明成runat="server",这个不重要了,你要的效果不需要使用后台代码的,除非你特意想要这个效果。