i amusing server.transfer to transfer values frm one aspx to another
my values are in array. i want to reatin the values on post back so nned to use viewstate
how do i use it
at present i have it in request.form method

x = Request.Form(listi(i).Trim + "sel")

Recommended Answers

All 4 Replies

HIii...
U can try session concepts

==>>View state is a hidden variable,
==>>Check following example, You can easily Save and use values from a view state.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
  // Sample ArrayList for the page.
  ArrayList PageArrayList;

  ArrayList CreateArray()
  {
    // Create a sample ArrayList.
    ArrayList result = new ArrayList(4);
    
    result.Add("item 1");
    result.Add("item 2");
    result.Add("item 3");
    result.Add("item 4");
    
    return result;
  }

  void Page_Load(object sender, EventArgs e)
  {
    if (ViewState["arrayListInViewState"] != null)
    {
      PageArrayList = (ArrayList)ViewState["arrayListInViewState"];
    }
    else
    {
      // ArrayList isn't in view state, so we need to load it from scratch.
      PageArrayList = CreateArray();
    }
    // Code that uses PageArrayList.
  }
    
  void Page_PreRender(object sender, EventArgs e)
  {
    // Save PageArrayList before the page is rendered.
    ViewState.Add("arrayListInViewState", PageArrayList);
  }
</script>

<html  >
<head runat="server">
    <title>View state sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

Try this

//Store an array in to a  ViewState
ArrayList arrayVariable = new ArrayList();
ViewState["myArray"] =  arrayVariable;
//Retrive array from ViewState
arryVariable = (ArrayList) ViewState["myArray"]

am using request.form for collecting the data from another page
listitems(i) is a varaible which hasa collection of few controls str = Request.Form(listitems(i).Trim + "sel") using the above i get the desired results
but i want the same to be used using viewstate so that the values can be stored on postbacks . how do i use it

i tried the below but didnot solve the problm

ViewState("str") = listitems(i).Trim + "sel"
str = ViewState("str").ToString()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.