文本框验证不成功 [英] textbox validation is not successful
本文介绍了文本框验证不成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Page_Load事件中,一些信息存储在textboxes中。事实上,他看到了他的个人资料信息进行编辑。当我更改一些文本框信息时,例如我将杰克改为alex并点击保存更改按钮杰克被保存在DataBase.i中不知道出了什么问题。
in Page_Load Event some information store in textboxes.in fact he see his profile information for editing.when i change some textboxes information for example i change jack to alex and click save changes button jack were save in DataBase.i do not know what is wrong.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
namespace Sanjesh_begin_8_farvardin
{
public partial class EditProfile : System.Web.UI.Page
{
public string constring = "server=localhost;database=SanjeshOrganizationDB;Trusted_Connection=true";
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con0 = new SqlConnection(constring);
con0.Open();
SqlCommand com0 = new SqlCommand("select * from Profile_Information where Username='"+Session["Username"].ToString()+"'",con0);
SqlDataReader rdr = com0.ExecuteReader();
rdr.Read();
TextBox1.Text = rdr["Username"].ToString();
TextBox2.Text = rdr["FName"].ToString();
TextBox3.Text = rdr["LName"].ToString();
DropDownList1.SelectedItem.Value = "1391";
DropDownList2.SelectedItem.Value = "01";
DropDownList3.SelectedItem.Value = "01";
TextBox4.Text = rdr["LiveLocation"].ToString();
TextBox5.Text = rdr["Email_Address"].ToString();
TextBox6.Text = rdr["Reason_For_Registering"].ToString();
TextBox7.Text = rdr["Liking_Field"].ToString();
TextBox8.Text = rdr["Optional_Comment"].ToString();
con0.Close();
}
protected void Button1_Click(object sender, EventArgs e)//Save changes
{
SqlConnection con0 = new SqlConnection(constring);
con0.Open();
SqlCommand com0 = new SqlCommand("Update Profile_Information Set FName='" + TextBox2.Text + "',LName='" + TextBox3.Text + "',BirthDate='"+DropDownList1.SelectedItem+"-"+DropDownList2.SelectedItem+"-"+DropDownList3.SelectedItem+"',LiveLocation='"+TextBox4.Text+"',Email_Address='"+TextBox5.Text+"',Reason_For_Registering='"+TextBox6.Text+"',Liking_Field='"+TextBox7.Text+"',Optional_Comment='"+TextBox8.Text+"' where Username='" + TextBox1.Text + "'", con0);
try
{
com0.ExecuteNonQuery();
Label12.Visible = true;
Label12.Text = "Successfull";
Label12.ForeColor = Color.Green;
}
catch
{
Label12.Visible = true;
Label12.Text = "Error";
Label12.ForeColor = Color.Red;
}
}
}
}
推荐答案
请查看您自己的代码,我想你错过了
if(!IsPostBack){}
please look in to your own code ,i think you missed
if (!IsPostBack){}
if (!IsPostBack)
{
//put you code to bind the control values
SqlConnection con0 = new SqlConnection(constring);
con0.Open();
SqlCommand com0 = new SqlCommand("select * from Profile_Information where Username='"+Session["Username"].ToString()+"'",con0);
SqlDataReader rdr = com0.ExecuteReader();
rdr.Read();
TextBox1.Text = rdr["Username"].ToString();
TextBox2.Text = rdr["FName"].ToString();
TextBox3.Text = rdr["LName"].ToString();
DropDownList1.SelectedItem.Value = "1391";
DropDownList2.SelectedItem.Value = "01";
DropDownList3.SelectedItem.Value = "01";
TextBox4.Text = rdr["LiveLocation"].ToString();
TextBox5.Text = rdr["Email_Address"].ToString();
TextBox6.Text = rdr["Reason_For_Registering"].ToString();
TextBox7.Text = rdr["Liking_Field"].ToString();
TextBox8.Text = rdr["Optional_Comment"].ToString();
con0.Close();
}
快乐编码
Happy coding
或许在按钮中关闭连接解决... ....试试看,其他一切看起来很好
perhaps closing connection in button solves....... try that, all else looks fine
使用
if(!IsPostBack)
{
}
页面加载
Use
if (!IsPostBack)
{
}
in page load
这篇关于文本框验证不成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文