Note that there are some explanatory texts on larger screens.

plurals
  1. POpageload in c#
    primarykey
    data
    text
    <p>Here is a piece of code that I've written. The problem that I'm having is: When i click a button in the gridview "rowcommand" adds the item to an arraylist which works fine. After the user clicks the button the page loads again and it goes to "rowcommand" AGAIN! As a result the same value is added to the arraylist.</p> <p>Is this something regarding postback? if it's I dont think I've understood it clearly enough! what seems to be wrong here?</p> <p>//edit 2: entire code block</p> <pre><code>public partial class Action_k : System.Web.UI.Page { ArrayList array; ArrayList tmpArrayList = new ArrayList(); string itemIDs = string.Empty; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { if (Session["username"] == null) { Session["anonuser"] = "anon"; Label1.Text = ""; userLabel.Text = ""; ImageButton1.ImageUrl = "~/images/logink.gif"; ImageButton1.PostBackUrl = "~/Login_k.aspx"; } else { userLabel.Text = Session["username"].ToString(); Label1.Text = "Your logged in as: "; ImageButton1.ImageUrl = "~/images/logoutk.gif"; } if (Session["array"] == null) { array = new ArrayList(); Session.Add("array", array); } } array = Session["array"] as ArrayList; } public void GridView2_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "AddToCart") { int index = Convert.ToInt32(e.CommandArgument); string items = GridView2.DataKeys[index].Value.ToString(); array.Add(items); Response.Redirect("ShoppingCart_k.aspx?itemID=" + items); } } } </code></pre> <p>Thanks,</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload