locked
Ajax postback always always choose first value from the dropdown RRS feed

  • Question

  • User-802727565 posted

    I have page with couple of dropdowns and excel download button, on download button click ajax postback dropdownlist always choose first value as selected item.

    But the selected item was 3. Can anyone help me to fix this.

    Thanks,

    Paps

    Thursday, December 5, 2013 5:35 PM

All replies

  • User2103319870 posted

    Hi,

    Ensure that you are not populating the dropdownlist on every postback.

    If you are binding the dropdown on postback try to wrap the databinding code inside a !IsPostback section like given below

    protected void Page_Load(object sender, EventArgs e)
    
        {
    
            if (!IsPostBack)
    
            {
    
                //code to bind dropdown
    
            }
    
        }

    One more suggestion is if you are using an update panel your dropdownlist should be present within that panel. This is because Selected value will only be available at the sever if the the page containing the dropdownlist control is posted back.

    Thursday, December 5, 2013 6:37 PM
  • Thursday, December 5, 2013 10:58 PM
  • User-802727565 posted

    Thanks for everyone's response. I'm binding the dropdown values in (!.Postback) but still when i click on export excel button, it is taking the first value from the dropdown as seleted value and actual is different.

    Friday, December 6, 2013 5:04 AM
  • User-933407369 posted

    hi suresh@net,

    you need to check out your code and make sure the dropdownlist datasource is not postback .

    Can you post the complete  markup or provide a simple demo, which can easily reproduce the problem?
    In order to help us to understand your issue better.

    Thanks.

    Monday, December 9, 2013 2:45 AM