locked
CascadingDropDown - Resets after postback RRS feed

  • Question

  • User1328469565 posted

    I have a set of filters that make use of CascadingDropDown. When a user has selected values in the CascadingDropDown and then clicks a button which posts the page back, all the dropdowns reset themselves back and forget the values the user selected before the postback. Is this normal?

    Saturday, March 14, 2015 6:46 PM

Answers

  • User281315223 posted

    What does your Page_Load event look like?

    Generally if this is occurring, it's because you might be binding your values within the Page_Load event, but you won't want to do that every time the page is loaded (just the initial load). You can handle that by checking if a PostBack occurred using the IsPostBack property :

    protected void Page_Load(object sender, EventArgs e)
    {                        
          // Check if it is the initial load
          if(!IsPostBack)
          {
              // It is the initial load, initially bind your DropDown items
              YourDropDownList.DataSource = GetYourValuesHere();
              YourDropDownList.DataBind();
          }
          else
          {
              // Handle any specific logic here, although I doubt you want to rebind your values (as that might reset them)
          }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 15, 2015 8:18 AM
  • User61956409 posted

    Hi vibez,

    Thanks for your post.

    Firstly, as Rion said, you could bind your DropDownList only when the page is rendered for the first time.

    Secondly, you could try to implement CascadingDropDown using Ajax Control Toolkit CascadingDropdown.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 16, 2015 5:14 AM

All replies

  • User281315223 posted

    What does your Page_Load event look like?

    Generally if this is occurring, it's because you might be binding your values within the Page_Load event, but you won't want to do that every time the page is loaded (just the initial load). You can handle that by checking if a PostBack occurred using the IsPostBack property :

    protected void Page_Load(object sender, EventArgs e)
    {                        
          // Check if it is the initial load
          if(!IsPostBack)
          {
              // It is the initial load, initially bind your DropDown items
              YourDropDownList.DataSource = GetYourValuesHere();
              YourDropDownList.DataBind();
          }
          else
          {
              // Handle any specific logic here, although I doubt you want to rebind your values (as that might reset them)
          }
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 15, 2015 8:18 AM
  • User61956409 posted

    Hi vibez,

    Thanks for your post.

    Firstly, as Rion said, you could bind your DropDownList only when the page is rendered for the first time.

    Secondly, you could try to implement CascadingDropDown using Ajax Control Toolkit CascadingDropdown.

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 16, 2015 5:14 AM