Reputation: 68
I've been having a tough time with updating my text boxes and could really use some help. So basically, I have a popup panel for the user to select a value that I then populate into a certain text box.
I am certain that the problem is either very simple to solve, or that I'm confused on what post back actually does. Here is a snippit of my code below:
protected void grvSearchRecords_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (string.Compare(e.CommandName, "EditRow", true) == 0)
{
long nMagic2Value = Convert.ToInt64(e.CommandArgument);
string tmp = GetItem(nMagic2Value, currentTableName);
textBox1.Text = tmp;
Debug.WriteLine(textBox1.Text.ToString());
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "SearchRecords", "$(document).ready(function(){ $('#mask, #divSearchRecordsGrid').fadeOut(\"fast\"); });", true);
}
}
The "tmp" variable grabs the value I need and assigns it to the text box.
I then run a Debug statement and confirm that the value is correctly assigned to the box. As soon as the function ends, however, that assigned value is lost, and the text box never populates with the new value.
Upvotes: 1
Views: 3136
Reputation: 68
Okay, I just got it working. The textbox I was trying to change was part of a Content tag and nothing else. I enclosed it in an UpdatePanel and added a trigger for my GridView, and now it works!
The joys of learning a new language.
Upvotes: 0
Reputation: 45490
Wrap your code around a post back check
if (!IsPostBack)
{
//your code here
}
This will ensure that your code does not run when it is a post back, so your textBox will not be clear.
Post back means that the page is not being rendered for the first time, for example a page refresh.
Upvotes: 2