473,663 Members | 2,933 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.IsPostBa ck)
{
counttextboxes = 0;
ViewState.Add(" counttextboxes" , counttextboxes) ;

}

counttextboxes = (int) ViewState["counttextboxes "];
Label1.Text = counttextboxes. ToString();

}

ImageButton1_Cl ick has:

{

counttextboxes = (int) ViewState["counttextboxes "];
counttextboxes+ +;
ViewState.Add(" counttextboxes" , counttextboxes) ;
Label2.Text = Convert.ToStrin g(counttextboxe s);

}
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_cl ick.
If Label1 displays 5, label2 displays 6.
How to even them up? _Without_ this method on page load by the way:

if (Convert.ToBool ean(counttextbo xes))
counttextboxes = counttextboxes + 1;

Thank you for your time.
Nov 19 '05 #1
1 1042

"the friendly display name"
<th************ ********@discus sions.microsoft .com> wrote in message
news:4C******** *************** ***********@mic rosoft.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
21639
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 the results in the grid. Say you filter the grid for records that have a certain condition set to "NO" (in this case a checkbox). In this scenario the search returns one result. If I then check the checkbox ("YES") and save it, I now get my message...
3
2829
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 experiencing the "Viewstate corrupted" error message on a particular page, when that page is left for a period of time and I return to it again, and submit it again. The page in question has a drop-down list of various RSS news feeds I am...
1
1503
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 it, the viewstate does not seem to load for the user control upon sending it back down to the client. If I change the data again, then the viewstate DOES seem to be maintained. What gives?
2
1483
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 column of a DataSet filled on depends of the listbox's selected item... But I have the following problem: When I select a second item on the dropdown list, the text of the textboxes are the same, even when in debug time, it shows me another
3
17152
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 = CType( ViewState("mydata"), DataTable)
28
21129
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 share information across pages but have lots of information to cache for that page.Can you please advise which is the efficient way to do it.The page is a search function which has a minimum of 10000 visitors per day. Regards
9
4912
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 a static machinekey in the machine.config and that did not help. I believe that issue only occurred when there was an inconsistent viewstate error. The error I am faced with consistently occurs. Are there any known problems with the ViewState...
5
3268
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 bound to a datagrid on the same page. It works 90% of the time as expected. However, for some unknown reason, I randomly get the error below. The HttpException says there is an 'Invalid_Viewstate'. Ok, but why? I'm posting back to the same page. If...
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 page gets post back it gives following error Failed to load viewstate. The control tree into which viewstate is
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8778
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2764
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 we have to send another system
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.