473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ViewState problem

I have an arraylist which takes in values and im trying to add values to the
array list everytime the button is clicked. Im trying to use the viewstate
but seem to be getting the following build error.

'System.Web.UI.Control.ViewState' denotes a 'property' where a 'method' was
expected

Can someone please tell me what I have done wrong. Here is the code which I
have added to the web form below.

Thanks for your help
private ArrayList addresses;

private void Page_Load(object sender, System.EventArgs e)
{

if(!(ViewState["Addresses"]==null))
{
this.addresses = (ArrayList)ViewState("Addresses");
}
else
{
this.addresses = new ArrayList();
}

}

private void Button1_Click(object sender, System.EventArgs e)
{
Address newAddress = new Address();
newAddress.Address1 = this.TextBox1.Text.Trim();
newAddress.Address2 = this.TextBox2.Text.Trim();
newAddress.Address3 = this.TextBox3.Text.Trim();
newAddress.Address4 = this.TextBox4.Text.Trim();
newAddress.Address5 = this.TextBox5.Text.Trim();
newAddress.Address6 = this.TextBox6.Text.Trim();

this.addresses.Add(newAddress);
ViewState("Addresses") = this.addresses;
this.DataGrid1.DataSource = this.addresses;
this.DataGrid1.DataBind();
}
Jul 21 '05 #1
1 1734
You are trying to use paren to access the Address value from viewstate
instead of square brackets. So you are using syntax for calling a method
'ViewState' instead of accessing the indexed ViewState property.

"Stephen" <St*****@discussions.microsoft.com> wrote in message
news:8B**********************************@microsof t.com...
I have an arraylist which takes in values and im trying to add values to the array list everytime the button is clicked. Im trying to use the viewstate but seem to be getting the following build error.

'System.Web.UI.Control.ViewState' denotes a 'property' where a 'method' was expected

Can someone please tell me what I have done wrong. Here is the code which I have added to the web form below.

Thanks for your help
private ArrayList addresses;

private void Page_Load(object sender, System.EventArgs e)
{

if(!(ViewState["Addresses"]==null))
{
this.addresses = (ArrayList)ViewState("Addresses");
}
else
{
this.addresses = new ArrayList();
}

}

private void Button1_Click(object sender, System.EventArgs e)
{
Address newAddress = new Address();
newAddress.Address1 = this.TextBox1.Text.Trim();
newAddress.Address2 = this.TextBox2.Text.Trim();
newAddress.Address3 = this.TextBox3.Text.Trim();
newAddress.Address4 = this.TextBox4.Text.Trim();
newAddress.Address5 = this.TextBox5.Text.Trim();
newAddress.Address6 = this.TextBox6.Text.Trim();

this.addresses.Add(newAddress);
ViewState("Addresses") = this.addresses;
this.DataGrid1.DataSource = this.addresses;
this.DataGrid1.DataBind();
}

Jul 21 '05 #2

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

Similar topics

9
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
by: Steve Drake | last post by:
All, I have a CONTROL that contains 1 control (Control ONE), the 1 control that it can contain 1 or 2 control (Control A and B). Control A, raises and event and Control ONE receives this event...
2
by: Ben Rush | last post by:
Hello World, Okay, I have spent the day browsing the newsgroups and reading up on article after article concerning ViewState corruption and so forth, and I have a couple questions. We...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
2
by: Janaka | last post by:
We have managed to lock down 99% of the application errors occurring in our asp.net sites. The only errors which occur on a regular basis now are viewstate errors. We have disabled viewstate on...
6
by: John | last post by:
Hi all, I am using dynamic user controls within my web app and these controls are loaded into placeholders via the LoadControl method. My problem is this: I have usercontrolA loaded into a...
2
by: epigram | last post by:
I'm responding to a button click event on an asp.net web form. I then need to retrieve the value from a TextBox control and I want to compare it against the control's previous value to see if it...
6
by: hlubocky | last post by:
I thought I had a good grasp of the problem related to dynamically creating controls, but it appears that as my application grew in complexity, the problem has resurfaced. As I understand it, in...
1
by: jelle.huygen | last post by:
Hello, I have a problem in ASP.NET 2.0 with the viewstate of my dynamically added user control. I have reproduced the problem with a very simple user control and a very simple page. On my...
0
by: Scott Roberts | last post by:
I always thought that the viewstate "keys" included the control ID. As long as the control IDs were unique, there shouldn't be any conflicts. Well, it appears that that may not be the case with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.