473,507 Members | 3,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ViewState chaos

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.
Nov 19 '05 #1
1 1032

"the friendly display name"
<th********************@discussions.microsoft.co m> wrote in message
news:4C**********************************@microsof t.com...
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 executes before control events execute. So, you are displaying
the value of the counttextboxes value before you are incrementing it in the
click event.

Mythran

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
21627
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
3
2817
by: Trevor Andrew | last post by:
Hi There, I have a small ASP.NET application under development. I am using VS.NET 2002 (2003 upgrade is on the way) with .NET Framework 1.1. It is hosted on a web hosting service in the US. I am...
1
1496
by: John | last post by:
Hi all, I have a problem with viewstate being maintained. I use LoadControl to load a user control and the data is sent down to the client correctly. However, when I change some data and post...
2
1474
by: Andrés Giraldo | last post by:
Hi! I'm adding rows dinamically to a System.Web.UI.WebControls.Table, on depends on a dropdown listbox's selected item, on a Cell of the table I'm adding a TextBox, it's Text property it's a...
3
17135
by: Pradeep | last post by:
Hi, I am storing the DataTable in a ViewState. ViewState("mydata") = dsRedemption.T_Redemption_Dtl Then I am casting the ViewState into a DataTable variable. Dim x As New DataTable x =...
28
21095
by: Vishwanathan Raman | last post by:
Hi I am aware of the technical differences.But would like to get it clarified.Given an oppurtunity is ViewState storage more efficient than Session based.I do not have a scenario where I need to...
9
4898
by: Jamie | last post by:
I am receiving an Invalid ViewState error after posting back to the same page twice. Consistently the error occurs after the second postback and not after the first. I have looked into creating...
5
3259
by: sjl | last post by:
I've got an .aspx webform for searching my database. It basically takes user input and passes it as a parm into a stored proc to search a table. The results are returned in a SQLDataReader and...
6
2058
by: hitendra15 | last post by:
Hi I have created web user control which has Repeater control and Linkbutton in ItemTemplate of repeater control, following is the code for this control On first load it runs fine but when...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7481
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.