button刷新页面 响应button的click消息,在响应函数里写插入数据库的代码,文本框的内容可以用this.TextBox1.Text拿到,再this.Response.Write(相应内容) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个实现的代码,你比着做就达到你要的效果了. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;"); SqlCommand cmd = new SqlCommand("select content from temp5 ", con); con.Open(); TextBox1.Text = cmd.ExecuteScalar().ToString(); con.Close(); } } protected void Button1_Click(object sender, EventArgs e) { string content = this.TextBox1.Text.Trim(); SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;"); SqlCommand cmd = new SqlCommand("update temp5 set content='"+content+"'", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } 保存和取数据我就不说了,相信你懂如3楼所说,不过页面加载时取数据显示时,请不要放在if (!IsPostBack) 块里,也就是把这个条件去掉。页面刷新嘛,你在VS工具上,用它的智能感知吧,我现在一下子记不得整个名字了。在protected void Button1_Click(object sender, EventArgs e) 里存入数据后,写上Server.Tran 这时VS的智能感知会提示一堆的方法的,反正就这几个字母开头的,参数是当前页面的URL:System.Web.HttpContext.Current.Request. 这里我也不记得了,你就靠VS的智能感知吧,看说明,反正就是当前页面URL的那个就是啦。其实刷新这个方法可以不用的,因为你保存数据回服务器后,再传回到客户端的页面相当于加载一遍,只要在页面加载时读取数据就得了,记得,读取数据显示时不要写在if (!IsPostBack)里 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { display(); } } protected void Button1_Click(object sender, EventArgs e) { string content = this.TextBox1.Text.Trim(); SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;"); SqlCommand cmd = new SqlCommand("update temp5 set content='"+content+"'", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); display(); }void display(){ SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;"); SqlCommand cmd = new SqlCommand("select content from temp5 ", con); con.Open(); TextBox1.Text = cmd.ExecuteScalar().ToString(); con.Close(); } 保存和取数据我就不说了,相信你懂 如3楼所说,不过页面加载时取数据显示时,请不要放在if (!IsPostBack) 块里,也就是把这个条件去掉。 页面刷新嘛,你在VS工具上,用它的智能感知吧,我现在一下子记不得整个名字了。 在protected void Button1_Click(object sender, EventArgs e) 里存入数据后, 写上Server.Tran 这时VS的智能感知会提示一堆的方法的,反正就这几个字母开头的, 参数是当前页面的URL:System.Web.HttpContext.Current.Request. 这里我也不记得了,你就靠VS的智能感知吧,看说明,反正就是当前页面URL的那个就是啦。 其实刷新这个方法可以不用的,因为你保存数据回服务器后,再传回到客户端的页面相当于加载一遍,只要在页面加载时读取数据就得了,记得,读取数据显示时不要写在if (!IsPostBack)里-------------------------------page_load事件里面最好加上if(!IsPostBack),上面最后的说法都是建立在不使用if(!IsPostBack)的基础上,但是这样每次提交数据库就很有可能执行一些根本不需要执行的代码,建议不要使用通常刷新都是建立一个公用查询的方法,在pageload调用一次,在保存数据库后又调用一次! lovehongyun 5楼说得没错! 打开页面,绑定gridvew,显示数据填写内容到textbox点击buttoninsert数据库然后重新绑定gridvew protected void Button1_Click(object sender, EventArgs e) { string content = this.TextBox1.Text.Trim(); SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;"); SqlCommand cmd = new SqlCommand("update temp5 set content='"+content+"'", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); session["display"]=session["display"].tostring()+"\n"+this.TextBox.text;Response.write(session["display"].tostring()); }保存的方法是复制上面兄弟们的;显示的方法这个是比较好的 ajax获取数据问题... iis问题 DataTable 上如何执行sql语句的 group by?多谢! ***讨论方案:如何对更新的内容作历史纪录?*** 目录树 点击B页Button,刷新A页! VB怎么写? 就剩10分了,不好意思! 判断如果数据查询不到的话 就不要输出 C# web页面里的a标签href="?acion=pass&repage=...",提交到本页面,点击一次,参数就累加一次,求解 那位提示一下,怎样实现想vs IDE那样的自动隐藏功能? 关于ASP.NET在线编译的问题 asp.net远程关闭进程的问题 Accordion 和 GridView控件的事件问题
{
if (!IsPostBack)
{
SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand("select content from temp5 ", con);
con.Open();
TextBox1.Text = cmd.ExecuteScalar().ToString();
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string content = this.TextBox1.Text.Trim();
SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand("update temp5 set content='"+content+"'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close(); }
块里,也就是把这个条件去掉。页面刷新嘛,你在VS工具上,用它的智能感知吧,我现在一下子记不得整个名字了。
在protected void Button1_Click(object sender, EventArgs e)
里存入数据后,
写上Server.Tran 这时VS的智能感知会提示一堆的方法的,反正就这几个字母开头的,参数是当前页面的URL:System.Web.HttpContext.Current.Request. 这里我也不记得了,你就靠VS的智能感知吧,看说明,反正就是当前页面URL的那个就是啦。其实刷新这个方法可以不用的,因为你保存数据回服务器后,再传回到客户端的页面相当于加载一遍,只要在页面加载时读取数据就得了,记得,读取数据显示时不要写在if (!IsPostBack)里
{
if (!IsPostBack)
{
display();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string content = this.TextBox1.Text.Trim();
SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand("update temp5 set content='"+content+"'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
display(); }void display()
{
SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand("select content from temp5 ", con);
con.Open();
TextBox1.Text = cmd.ExecuteScalar().ToString();
con.Close();
}
块里,也就是把这个条件去掉。 页面刷新嘛,你在VS工具上,用它的智能感知吧,我现在一下子记不得整个名字了。
在protected void Button1_Click(object sender, EventArgs e)
里存入数据后,
写上Server.Tran 这时VS的智能感知会提示一堆的方法的,反正就这几个字母开头的, 参数是当前页面的URL:System.Web.HttpContext.Current.Request. 这里我也不记得了,你就靠VS的智能感知吧,看说明,反正就是当前页面URL的那个就是啦。 其实刷新这个方法可以不用的,因为你保存数据回服务器后,再传回到客户端的页面相当于加载一遍,只要在页面加载时读取数据就得了,记得,读取数据显示时不要写在if (!IsPostBack)里
-------------------------------
page_load事件里面最好加上if(!IsPostBack),上面最后的说法都是建立在不使用if(!IsPostBack)的基础上,但是这样每次提交数据库就很有可能执行一些根本不需要执行的代码,建议不要使用通常刷新都是建立一个公用查询的方法,在pageload调用一次,在保存数据库后又调用一次!
说得没错!
填写内容到textbox
点击button
insert数据库
然后重新绑定gridvew
{
string content = this.TextBox1.Text.Trim();
SqlConnection con = new SqlConnection("server=.;database=try;uid=sa;pwd=;");
SqlCommand cmd = new SqlCommand("update temp5 set content='"+content+"'", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
session["display"]=session["display"].tostring()+"\n"+this.TextBox.text;
Response.write(session["display"].tostring());
}
保存的方法是复制上面兄弟们的;显示的方法这个是比较好的