为何后台得到的数据与输入的不一致
这是前台代码。
<body>
<div runat="server">
<form runat="server" id="from1">
<table >
<tr >
<td>时间:</td><td><input id="time" type="text" runat="server" value="" /></td>
<td>发布者:</td><td><input id="name" type="text" runat="server" value="" /></td>
</tr>
<tr>
<td >标题:</td><td colspan="3"><textarea id="title" type="text" runat="server" value="" rows="0" cols="43"></textarea></td>
</tr>
<tr>
<td colspan="4" align="center">内容:</td>
</tr>
<tr>
<td colspan="4"><textarea runat="server" id="neirong" rows="10" cols="50"></textarea> </td>
</tr>
<tr>
<td align="center"><asp:Button ID="ok" Text="保存" runat="server" onclick="ok_Click" /></td>
<td align="center"><asp:Button ID="chakan" Text="查看" runat="server" onclick="chakan_Click" /></td>
<td align="center"><asp:Button ID="clear" Text="清空" runat="server" onclick="clear_Click" /></td>
<td align="center"><asp:Button ID="update" Text="更新" runat="server" onclick="update_Click" /></td>
</tr>
<tr>
<td colspan=4><asp:Label runat="server" ID="oneid" Text="" Visible="false"/></td>
</tr>
</table>
</form>
</div>
</body>
我是通过GridView通过编辑跳到这张页面上来,对应各个值也能正确赋值。现在想修改信息。
如下
protected void update_Click(object sender, EventArgs e)
{
string strname=this.name.Value.Trim();
string strneirong=this.neirong .Value.Trim();
string strtime=this.time.Value.Trim();
string strtitle=this.title.Value.Trim();
int stroneid = Convert.ToInt32( this.oneid.Text.Trim());//这个是对应的ID值我保存在页面的一个控件里。
if (strtime.Length == 0 || strname.Length == 0 || strtitle.Length == 0 || strneirong.Length == 0)
{
Response.Write("<script>alert('信息输入不能为空')</script>");
return;
}
string sql = "update xw set name='" + strname + "',neirong='" + strneirong + "',timetime='" + strtime + "',title='" + strtitle + "' where id='"+stroneid+"'";
SqlConnection conn = new SqlConnection("server=150.0.0.1;uid=pp;pwd=pp;database=ss");
conn.Open();
SqlCommand com = new SqlCommand(sql, conn);
com.ExecuteNonQuery();
Response.Redirect("chakan.aspx");
}
但我发现
string strname=this.name.Value.Trim();
string strneirong=this.neirong .Value.Trim();
string strtime=this.time.Value.Trim();
string strtitle=this.title.Value.Trim();得到的值仍然为之前页面跳转过来的赋值。无论输入任何值都是原来的值。
我是新手大家能帮帮忙不?谢谢!!!