Question

I'm having a problem concerning my website not running the code behind an ItemCommand run by my Repeater.

Here are some snippets of what I have in my C# code:

protected void Page_Load()
    {
        if (!Page.IsPostBack)
        {
            ddlGender.Items.Insert(0, new ListItem("-", "%"));
            ddlMerk.Items.Insert(0, new ListItem("-", "%"));
            ddlType.Items.Insert(0, new ListItem("-", "%"));
        }

        if (Page.IsPostBack)
        {
            Response.Redirect(String.Format("Catalogus.aspx?gender={0}&merkid={1}&type={2}", ddlGender.SelectedValue, ddlMerk.SelectedValue, ddlType.SelectedValue));
        }

    }

    protected void rCatalogus_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "voegToe")
        {
                HttpCookie winkelmandje = new HttpCookie("Winkelmandje");
                string product = (string)e.CommandArgument;
                winkelmandje[product] = "Test";
                winkelmandje.Expires = DateTime.Now.AddDays(2);
                Response.Cookies.Add(winkelmandje);

            Label1.Text = "HALSKFDHSALKFDJAS";
        }
    }

It is noteworthy that I've set my three DropDownLists as AutoPostBack, so they trigger the IsPostBack event which fills the QueryStrings.

Now I noticed that when I comment out the 'if (Page.IsPostBack)' section, the event triggers just fine. So I figured that the Response.Redirect is preventing the event from firing, am I correct? I would like to find a way for the event to fire and the PostBack with the Response.Redirect to happen as well, but I have as of yet, not found a way.

I sincerely hope any of you can help me and I would be grateful.

Thank you.

Was it helpful?

Solution

if you want your page to "redirect" only during the ItemCommand event then you can remove it during the Page_Load and move inside the ItemCommand event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top