textbox获取当前输入的值

lixupeng5258 2012-01-10 04:14:13
我要做一个界面用于修改用户信息,打开页面时页面会自动加载用户原来的信息,用户通过手动输入新的信息,按“确定”键保存。但我按“确定”后无法保存新的数据,数据库里还是原来的数据。
上网问了下,好像要在protected void Page_Load(object sender, EventArgs e)下写一个 if(!IsPostBack){}的,但本人对这个不太了解,大虾门解释下。还有假设textbox名字叫txtName,我要获取自己输入的新数据,if(!IsPostBack){}里面应该怎么写啊??
...全文
937 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
大神们帮帮忙啊,小弟的毕业设计就靠你们了。。3Q
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 zh6335901 的回复:]

[Quote=引用 15 楼 lixupeng5258 的回复:]

引用 14 楼 zh6335901 的回复:

你是不是把string str=txtName.Text写在if(!IsPostBack)里了?要把它写在外面

if(!IsPostBack)里我不知道写什么,就没写任何东西,我把源码发出来吧

using System;
us……
[/Quote]

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == false)
{
Response.Write("<script>alert('请选择要上传的Word文档!')</script>");
}
else
{
string Fullname = this.FileUpload1.FileName;
string Type = Fullname.Substring(Fullname.LastIndexOf(".") + 1);
int filesize = FileUpload1.PostedFile.ContentLength;
if (Type == "doc" || Type == "docx")
{
if (filesize > 10 * 1024 * 1024)
{
Response.Write("<script>alert('文件超过规定的大小,不得超过10M!')</script>");
}
else
{
string Wpath = "files\\" + Fullname;
System.IO.File.Delete(Server.MapPath("files") + "\\" + Fullname);
this.FileUpload1.SaveAs(Server.MapPath("files") + "\\" + Fullname);
data info = new data();
string typeid = DropDownList1.SelectedValue;
string remark = TextBox2.Text;
info.modifymanus(Label9.Text,typeid,remark,Wpath);
Response.Write("<script language='javascript'>alert('修改稿件成功!')</script>");
}
}
}
}
下面是数据库操作的代码:

public void modifymanus(string manus_title,string type_name,string remark,string wpath)
{
SqlConnection con = db.ceratcon();
con.Open();
string sqlString = "update Manus set Type_ID = (select Type_ID from Type where Type_Name = '" + type_name + "'),Manus_Note = '" + remark + "',Manus_State ='待审',Manus_Address = '" + wpath + "',Reviewer_Comments =NULL,Last_Comments = NULL where Manus_Title = '" + manus_title + "'";
SqlCommand cmd = new SqlCommand();
cmd.Connection = (SqlConnection)con;
cmd.CommandText = sqlString;
cmd.ExecuteNonQuery();
con.Close();
}
zh6335901 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 lixupeng5258 的回复:]

引用 14 楼 zh6335901 的回复:

你是不是把string str=txtName.Text写在if(!IsPostBack)里了?要把它写在外面

if(!IsPostBack)里我不知道写什么,就没写任何东西,我把源码发出来吧

using System;
using System.Collections.Generic;
usin……
[/Quote]
请把有问题的那段发上来
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 zh6335901 的回复:]

你是不是把string str=txtName.Text写在if(!IsPostBack)里了?要把它写在外面
[/Quote]
if(!IsPostBack)里我不知道写什么,就没写任何东西,我把源码发出来吧

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class pend : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{

}
Label1.Text = Session["username"].ToString();
if (Session["position"].ToString() == "author")
{
Label2.Text = "作者";
}
else if (Session["position"].ToString() == "edit")
{
Label2.Text = "编辑";
}
else if (Session["position"].ToString() == "reviewer")
{
Label2.Text = "专家";
}
string xman = Session["Title"].ToString();
SqlConnection con = db.ceratcon();
con.Open();
string sqlString = "select m.Manus_Title,a.Author_name,t.type_Name,m.Manus_Note,m.Reviewer_Comments,m.Last_Comments from Manus m,Author a,Type t where m.Author_ID=a.Author_ID and m.Type_ID=t.Type_ID and Manus_Title = '" + xman + "'";
SqlCommand cmd = new SqlCommand(sqlString, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
Label9.Text = dt.Rows[0]["Manus_Title"].ToString();
Label4.Text = dt.Rows[0]["Author_Name"].ToString();
DropDownList1.Text = dt.Rows[0]["Type_Name"].ToString();
TextBox2.Text = dt.Rows[0]["Manus_Note"].ToString();
Label7.Text = dt.Rows[0]["Reviewer_Comments"].ToString();
Label8.Text = dt.Rows[0]["Last_Comments"].ToString();
}

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == false)
{
Response.Write("<script>alert('请选择要上传的Word文档!')</script>");
}
else
{
string Fullname = this.FileUpload1.FileName;
string Type = Fullname.Substring(Fullname.LastIndexOf(".") + 1);
int filesize = FileUpload1.PostedFile.ContentLength;
if (Type == "doc" || Type == "docx")
{
if (filesize > 10 * 1024 * 1024)
{
Response.Write("<script>alert('文件超过规定的大小,不得超过10M!')</script>");
}
else
{
string Wpath = "files\\" + Fullname;
System.IO.File.Delete(Server.MapPath("files") + "\\" + Fullname);
this.FileUpload1.SaveAs(Server.MapPath("files") + "\\" + Fullname);
data info = new data();
string typeid = DropDownList1.SelectedValue;
string remark = TextBox2.Text;
info.modifymanus(Label9.Text,typeid,remark,Wpath);
Response.Write("<script language='javascript'>alert('修改稿件成功!')</script>");
}
}
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session["type"] = "author_pend";
Response.Redirect("main.aspx");

}
}
zh6335901 2012-01-10
  • 打赏
  • 举报
回复
你是不是把string str=txtName.Text写在if(!IsPostBack)里了?要把它写在外面
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zhangzhen900530 的回复:]

引用 6 楼 lixupeng5258 的回复:

引用 5 楼 zhangzhen900530 的回复:

C# code
string str=txtName.Text

这个我试过,没用的,str里还是原来的数据,新的数据没有获取到

哥是你程序问题,你也不贴源码,哪个晓得哪里有问题嘛
[/Quote]

protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile == false)
{
Response.Write("<script>alert('请选择要上传的Word文档!')</script>");
}
else
{
string Fullname = this.FileUpload1.FileName;
string Type = Fullname.Substring(Fullname.LastIndexOf(".") + 1);
int filesize = FileUpload1.PostedFile.ContentLength;
if (Type == "doc" || Type == "docx")
{
if (filesize > 10 * 1024 * 1024)
{
Response.Write("<script>alert('文件超过规定的大小,不得超过10M!')</script>");
}
else
{
string Wpath = "files\\" + Fullname;
System.IO.File.Delete(Server.MapPath("files") + "\\" + Fullname);
this.FileUpload1.SaveAs(Server.MapPath("files") + "\\" + Fullname);
data info = new data();
string typeid = DropDownList1.SelectedValue;
string remark = TextBox2.Text;
info.modifymanus(Label9.Text,typeid,remark,Wpath);
Response.Write("<script language='javascript'>alert('修改稿件成功!')</script>");
}
}
}
}
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 akgjh1 的回复:]

调试的时候 查看修改数据库时传入的值 确认一下是不是读取的时间不对
我也都是直接用txtName.Text的
[/Quote]
调试的时候,显示str是原来的数据,新数据就是没重新赋值给txtName
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 kongwei521 的回复:]

你确认你更新的SQL语句有没有问题?还是没得到txtName.Text重新输入的内容。
[/Quote]
我确定没问题,其他的数据都可以更新,就是这个txtName里的数据还是原来的数据
zhangzhen900530 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 lixupeng5258 的回复:]

引用 5 楼 zhangzhen900530 的回复:

C# code
string str=txtName.Text

这个我试过,没用的,str里还是原来的数据,新的数据没有获取到
[/Quote]
哥是你程序问题,你也不贴源码,哪个晓得哪里有问题嘛
mizuho_2006 2012-01-10
  • 打赏
  • 举报
回复
if(!IsPostBack){}

如果是第一次进入页面(而不是postback,即提交后的页面)
akgjh1 2012-01-10
  • 打赏
  • 举报
回复
调试的时候 查看修改数据库时传入的值 确认一下是不是读取的时间不对
我也都是直接用txtName.Text的
蝶恋花雨 2012-01-10
  • 打赏
  • 举报
回复
你确认你更新的SQL语句有没有问题?还是没得到txtName.Text重新输入的内容。
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zhangzhen900530 的回复:]

C# code
string str=txtName.Text
[/Quote]
这个我试过,没用的,str里还是原来的数据,新的数据没有获取到
zhangzhen900530 2012-01-10
  • 打赏
  • 举报
回复
string str=txtName.Text
guoyanhong1111 2012-01-10
  • 打赏
  • 举报
回复
建议楼主多看看书,这些都有说明的!
lixupeng5258 2012-01-10
  • 打赏
  • 举报
回复
我主要是不知道如何获取txtName中自己新输入的值。改怎么解决
风之子1 2012-01-10
  • 打赏
  • 举报
回复
同意楼上的说法!
zh6335901 2012-01-10
  • 打赏
  • 举报
回复
IsPostBack是指是否是回传,如果是第一次进入页面为false,是回传的话true

110,570

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧