Changes of text in an asp web form not captured on btn_submit
I have an asp web form which is u开发者_高级运维sed for database entry located at
localhost/EnterNewData.aspx
I also want to use this form to view entries in the database by passing the database id
localhost/EnterNewData.aspx?id=12
This all works fine. What I want to do now is if I am viewing an entry and one of the fields is incorrect, I can change it in the form and click the submit button and update the entry. The code checks if an id has been passed and if it has then it does an SQL update instead of an insert, however, none of the data seems to be getting updated. It's not a database issue as I have stepped through the code and have found the error here:
protected void btnSubmit_Click(object sender, EventArgs e)
{
string name = HttpUtility.HtmlEncode(txtBxName.Text);
The value txtBxName.Text still holds the original text that was in the web form field when the page was loaded, not the new text that I have typed in there before pressing the submit button.
Any ideas would be extremely helpful.
Thanks
G
Can we see your Page_Load
event? It might be a case of specifying the following IF statement when pre-populating the values:
if (!Page.IsPostBack) {
//Pre-fill textboxes here
}
精彩评论