Click to See Complete Forum and Search --> : Keep values after page_load


Newbie998
December 18th, 2006, 02:33 PM
Hello

I have a form asking for name, address etc.
I have two buttons.
When the user presses the first button the content from the form is
presented in labels (on the same page).

When the second button is pressed, the content is inserted into a database.
Because there are two buttons, there are two methods:
protected void buttonName_Click(object sender, EventArgs e)

When the first button is clicked all strings containing values from the form will be null. Probably because the page reloads.

I need to keep the values, because the second button is for insterting to database. The only way I know is to make the strings static.
Like this:
static string name = textboxName.Text;
But that doesn't seem like a good idea.

How do I solve this the easiest way?

Thanks

TheCPUWizard
December 18th, 2006, 02:59 PM
Look at Page.IsPostBack and ViewState. Thaty should give you all your need.

Newbie998
December 18th, 2006, 06:46 PM
Who´s the man?
You are!!!

It did the trick..............

Thanks a lot....

TheCPUWizard
December 18th, 2006, 09:01 PM
Glad to help.... Just remember ratings matter :D

Newbie998
December 19th, 2006, 02:31 AM
Done =)