开发者

Why does dropdownlist selected option does not cause postback second Time?

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 = "";       开发者_JAVA百科      
        }
        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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜