views:

280

answers:

1

I have two dropdownlists ,selecting the first dropdown causes postback and second dropdown gets binded...

  • Why does the selected value of the first dropdown,once again selected does not cause postback?

EDIT:

 <asp:DropDownList ID="DLMatName" runat="server" OnSelectedIndexChanged="DlMeasurement_SelectedIndexChanged" AutoPostBack="true">
                                               </asp:DropDownList>


protected void DlMeasurement_SelectedIndexChanged(object sender, EventArgs e)
{

    if (DLMatName.SelectedIndex != 0)
    {
        DataTable dt = _materialInController.GetMeasurementsforMaterials(Convert.ToInt64(DLMatName.SelectedValue.ToString())).Tables[0];
        if (dt.Rows.Count > 1)
        {
            MeasurementTr.Visible = true;
            this.DlMeasurement.DataSource = dt;
            this.DlMeasurement.DataValueField = dt.Columns[0].ToString();
            this.DlMeasurement.DataTextField = dt.Columns[1].ToString();
            this.DlMeasurement.DataBind();
            this.DlMeasurement.Items.Insert(0, ListItem.FromString("Select"));
            this.LblMeasuremet.Visible = false;
            ErrorMsg.InnerHtml = "";             
        }
        else if (dt.Rows.Count == 1)
        {
            this.LblMeasuremet.Visible = true;
            this.LblMeasuremet.Text = dt.Rows[0].ItemArray[1].ToString();
            MeasurementTr.Visible = false;
            ErrorMsg.InnerHtml = "";       

        }
        else
        {

        }
    }
    else
    {
        MeasurementTr.Visible = false;
        this.LblMeasuremet.Visible = false;
        ErrorMsg.InnerHtml = "Select the materialType";
    }
    ScriptManager.RegisterClientScriptBlock(DLMatName, typeof(DropDownList), "Hideimage", "HideImageButtonDivforAdd();", true);

}

First time a selected value postbacks,the same when selected second time doesn't postback...

A: 

Are you rebinding the second dropdown on every postback of the page, i.e. in your Page_Load event do you have any code such as this:

protected void Page_Load(object sender, EventArgs e)
{
      if (DropDown1.SelectedIndex > 0)
      {
          // Rebind the second dropdown. 
      }
}

If so then you're missing a check to see if the page is posting back to itself (Page.IsPostBack) and this would cause your issue.

Robert W