G
Guest
Following problem:
I have on the page one (graphic-)button (its click even is wired), some
other stuff and of course the page_load function
Page_Load function has the following entry:
{
if (!Page.IsPostBack)
{
counttextboxes = 0;
ViewState.Add("counttextboxes", counttextboxes);
}
counttextboxes = (int) ViewState["counttextboxes"];
Label1.Text = counttextboxes.ToString();
}
ImageButton1_Click has:
{
counttextboxes = (int) ViewState["counttextboxes"];
counttextboxes++;
ViewState.Add("counttextboxes", counttextboxes);
Label2.Text = Convert.ToString(counttextboxes);
}
as you guessed, the problem is counttextboxes (an int, declared as protected
in the class).
If I click on the first button, thus activating button1_click,
counttextboxes gets indeed bigger. But on page_load (when I test it) it is
always one number smaller than it's on Imagebutton1_click.
If Label1 displays 5, label2 displays 6.
How to even them up? _Without_ this method on page load by the way:
if (Convert.ToBoolean(counttextboxes))
counttextboxes = counttextboxes + 1;
Thank you for your time.
I have on the page one (graphic-)button (its click even is wired), some
other stuff and of course the page_load function
Page_Load function has the following entry:
{
if (!Page.IsPostBack)
{
counttextboxes = 0;
ViewState.Add("counttextboxes", counttextboxes);
}
counttextboxes = (int) ViewState["counttextboxes"];
Label1.Text = counttextboxes.ToString();
}
ImageButton1_Click has:
{
counttextboxes = (int) ViewState["counttextboxes"];
counttextboxes++;
ViewState.Add("counttextboxes", counttextboxes);
Label2.Text = Convert.ToString(counttextboxes);
}
as you guessed, the problem is counttextboxes (an int, declared as protected
in the class).
If I click on the first button, thus activating button1_click,
counttextboxes gets indeed bigger. But on page_load (when I test it) it is
always one number smaller than it's on Imagebutton1_click.
If Label1 displays 5, label2 displays 6.
How to even them up? _Without_ this method on page load by the way:
if (Convert.ToBoolean(counttextboxes))
counttextboxes = counttextboxes + 1;
Thank you for your time.