asp.net 中textBox的值为什么改了后不变化
直接贴代码了,就是载入页面的时候,textbox值是有的,但是我在页面中改了这个值后,最后传给服务器的还是刚载入的值,这是为什么?MyMeansMyDataClass=n...
直接贴代码了,就是载入页面的时候,textbox值是有的,但是我在页面中改了这个值后,最后传给服务器的还是刚载入的值,这是为什么?
MyMeans MyDataClass = new MyMeans();
protected void Page_Load(object sender, EventArgs e)
{
pageDataBind();
}
private void pageDataBind()
{
SqlDataReader sdr1 = MyDataClass.getcom("select * from users where userID='" + Request.QueryString["UserID"] + "'");
if (sdr1.Read())
{
TextBox1.Text = sdr1[0].ToString();
TextBox2.Text = sdr1[1].ToString();
TextBox3.Text = sdr1[2].ToString();
TextBox4.Text = sdr1[3].ToString();
}
SqlDataReader sdr2 = MyDataClass.getcom("select roleID from User_Role where userID='" + Request.QueryString["UserID"] + "'");
if (sdr1.Read())
{
DropDownList1.SelectedValue=sdr2[0].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//pageDataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text);
MyDataClass.getsqlcom("update Users set userID='" + TextBox1.Text.Trim() + "', userName='" + TextBox2.Text.Trim() + "', userPass='" + TextBox3.Text.Trim() + "', userDep='" + TextBox4.Text.Trim() + "' where userID='"+Request.QueryString["UserID"]+"'");
MyDataClass.getsqlcom("update User_Role set userID='" + TextBox1.Text.Trim() + "', RoleID='" + DropDownList1.SelectedValue + "' where userID='"+Request.QueryString["UserID"]+"'");
Response.Write("<script language=javascript>");
Response.Write("window.alert('修改成功!');</script>");
pageDataBind();
} 展开
MyMeans MyDataClass = new MyMeans();
protected void Page_Load(object sender, EventArgs e)
{
pageDataBind();
}
private void pageDataBind()
{
SqlDataReader sdr1 = MyDataClass.getcom("select * from users where userID='" + Request.QueryString["UserID"] + "'");
if (sdr1.Read())
{
TextBox1.Text = sdr1[0].ToString();
TextBox2.Text = sdr1[1].ToString();
TextBox3.Text = sdr1[2].ToString();
TextBox4.Text = sdr1[3].ToString();
}
SqlDataReader sdr2 = MyDataClass.getcom("select roleID from User_Role where userID='" + Request.QueryString["UserID"] + "'");
if (sdr1.Read())
{
DropDownList1.SelectedValue=sdr2[0].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
//pageDataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(TextBox1.Text + TextBox2.Text + TextBox3.Text + TextBox4.Text);
MyDataClass.getsqlcom("update Users set userID='" + TextBox1.Text.Trim() + "', userName='" + TextBox2.Text.Trim() + "', userPass='" + TextBox3.Text.Trim() + "', userDep='" + TextBox4.Text.Trim() + "' where userID='"+Request.QueryString["UserID"]+"'");
MyDataClass.getsqlcom("update User_Role set userID='" + TextBox1.Text.Trim() + "', RoleID='" + DropDownList1.SelectedValue + "' where userID='"+Request.QueryString["UserID"]+"'");
Response.Write("<script language=javascript>");
Response.Write("window.alert('修改成功!');</script>");
pageDataBind();
} 展开
5个回答
展开全部
同意菜是菜鸟的鸟的意见,页面加载时需要判断是不是首次加载
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(!IsPostBack){}
不多说
不多说
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
二楼回答的很好
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看一下MyMeans 这个类 贴的代码没问题 应该是读取时的问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询