Web Textbox Control text not changing

G

Guest

Hi,
In my page load event I set the Text value of a TextBox control
as follows:

private void Page_Load(object sender, System.EventArgs e)
{
this.txtName = "Joe"
}

I have a button which needs to get the value of the txtName after any changes.
I change the value of text control after the page loads, but when I check
the value
when the button is clicked, the text control value remains "Joe".

private void btnSaveBottom_Click(object sender, System.EventArgs e)
{
string name = txtName.Text;

// name should be new current value entered in text control, but
// I keep getting "Joe"
}


Any ideas?
 
G

Guest

The Page.Load event is triggered on every postback therefore your text is
being re-initialized to "Joe" before the btnSaveBottom_Click is reached.
Change the Page_Load method to look like:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
this.txtName = "Joe";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top