ViewState problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen

    #1

    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.ViewSta te' 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(objec t sender, System.EventArg s e)
    {

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

    }

    private void Button1_Click(o bject sender, System.EventArg s e)
    {
    Address newAddress = new Address();
    newAddress.Addr ess1 = this.TextBox1.T ext.Trim();
    newAddress.Addr ess2 = this.TextBox2.T ext.Trim();
    newAddress.Addr ess3 = this.TextBox3.T ext.Trim();
    newAddress.Addr ess4 = this.TextBox4.T ext.Trim();
    newAddress.Addr ess5 = this.TextBox5.T ext.Trim();
    newAddress.Addr ess6 = this.TextBox6.T ext.Trim();

    this.addresses. Add(newAddress) ;
    ViewState("Addr esses") = this.addresses;
    this.DataGrid1. DataSource = this.addresses;
    this.DataGrid1. DataBind();
    }
  • Marina

    #2
    Re: ViewState problem

    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" <Stephen@discus sions.microsoft .com> wrote in message
    news:8BFE7165-4C8B-41BB-8732-4630F5CA1F6E@mi crosoft.com...[color=blue]
    > I have an arraylist which takes in values and im trying to add values to[/color]
    the[color=blue]
    > array list everytime the button is clicked. Im trying to use the[/color]
    viewstate[color=blue]
    > but seem to be getting the following build error.
    >
    > 'System.Web.UI. Control.ViewSta te' denotes a 'property' where a 'method'[/color]
    was[color=blue]
    > expected
    >
    > Can someone please tell me what I have done wrong. Here is the code which[/color]
    I[color=blue]
    > have added to the web form below.
    >
    > Thanks for your help
    >
    >
    > private ArrayList addresses;
    >
    > private void Page_Load(objec t sender, System.EventArg s e)
    > {
    >
    > if(!(ViewState["Addresses"]==null))
    > {
    > this.addresses = (ArrayList)View State("Addresse s");
    > }
    > else
    > {
    > this.addresses = new ArrayList();
    > }
    >
    > }
    >
    > private void Button1_Click(o bject sender, System.EventArg s e)
    > {
    > Address newAddress = new Address();
    > newAddress.Addr ess1 = this.TextBox1.T ext.Trim();
    > newAddress.Addr ess2 = this.TextBox2.T ext.Trim();
    > newAddress.Addr ess3 = this.TextBox3.T ext.Trim();
    > newAddress.Addr ess4 = this.TextBox4.T ext.Trim();
    > newAddress.Addr ess5 = this.TextBox5.T ext.Trim();
    > newAddress.Addr ess6 = this.TextBox6.T ext.Trim();
    >
    > this.addresses. Add(newAddress) ;
    > ViewState("Addr esses") = this.addresses;
    > this.DataGrid1. DataSource = this.addresses;
    > this.DataGrid1. DataBind();
    > }[/color]


    Comment

    Working...