OnSelectedIndexChanged不会为1 DropDownList触发,但适用于另一个

时间:2011-07-04 09:50:48

标签: c# asp.net drop-down-menu

我正在使用2个DropDownList,1个表之前和之后1个。 这些DropDownList允许设置表内容。 我的问题是,第一个DropDownList工作正常,但第二个的OnSelectedIndexChanged事件不会触发。

 <table width="100%">
    <tr>
        <td>
            <asp:Table ID="tblDates" runat="server" Width="100%">
                <%--Premier et Dernier jour de la semaine--%>
                <asp:TableRow ID="tblRow" runat="server">
                    <asp:TableCell ID="tblcell" runat="server" HorizontalAlign="left" ColumnSpan="2">
                        <h2>
                            <asp:Literal ID="lblTitre" runat="server" OnPreRender="LblTitreRender" /></h2>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow Height="30px" ID="tblr" runat="server">
                    <%--Premier et Dernier jour de la semaine--%>
                    <asp:TableCell ID="tblcell3" runat="server" VerticalAlign="Top" Style="margin-bottom: 5px;">
                        <asp:Literal ID="lblTitrePeriode" runat="server" OnPreRender="LblTitrePeriodeRender" />
                        <asp:HiddenField ID="hdnSemaine" runat="server" EnableViewState="true" />
                        <%--Numéro de la semaine--%>
                        <asp:HiddenField ID="hdnMois" runat="server" EnableViewState="true" />
                        <%--Numéro du mois--%>
                        <asp:HiddenField ID="hdnAnnee" runat="server" EnableViewState="true" />
                        <%--Année--%>
                        <asp:HiddenField ID="hdnIdFicheActivite" runat="server" EnableViewState="true" />
                        <%--Id de la fiche d'activité correspondante--%>
                    </asp:TableCell><%--Boutons suivant et précédent et numéro de la semaine--%>
                    <asp:TableCell ID="TableCell7" runat="server" valign="right">
                        <asp:Table ID="tblSemaine" runat="server" HorizontalAlign="Right">
                            <asp:TableRow ID="TableRow4" runat="server">
                                <asp:TableCell ID="TableCell8" runat="server" HorizontalAlign="Right" VerticalAlign="Top">
                                    <asp:Button ID="btnPrev" runat="server" Text=" < " CssClass="bouton" OnClick="btnPrev_Click"
                                        EnableViewState="false" OnPreRender="btnPrevRender" />
                                    &nbsp;
                                </asp:TableCell>
                                <asp:TableCell runat="server" ID="tdSemaines">
                                    <asp:DropDownList ID="ddlSemaine" runat="server" OnPreRender="DdlSemaineLoad" OnSelectedIndexChanged="ddlSemaineChanged"
                                        EnableViewState="true" AutoPostBack="true" />
                                </asp:TableCell>
                                <asp:TableCell ID="TableCell9" runat="server" VerticalAlign="Top">
                                    &nbsp;
                                    <asp:Button ID="btnNext" runat="server" Text=" > " CssClass="bouton" OnClick="btnNext_Click"
                                        EnableViewState="false" OnPreRender="btnNextRender" />
                                </asp:TableCell>
                            </asp:TableRow>
                        </asp:Table>
                    </asp:TableCell>
                </asp:TableRow>
            </asp:Table>
        </td>
    </tr>
    <tr>
        <td>
            <asp:HiddenField ID="hdnCh_LUN" runat="server" />
            <asp:HiddenField ID="hdnCh_MAR" runat="server" />
            <asp:HiddenField ID="hdnCh_MER" runat="server" />
            <asp:HiddenField ID="hdnCh_JEU" runat="server" />
            <asp:HiddenField ID="hdnCh_VEN" runat="server" />
            <%--Tableau en tête--%>
            <asp:Table ID="tblProjet" Width="100%" runat="server" CellSpacing="0" EnableViewState="true">
                <asp:TableRow ID="trTache" runat="server" CssClass="EnTete">
                    <asp:TableCell Text="Tâche" Height="20px" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell ID="chAl" Width="60" CssClass="padL80" Text="<%$ Resources:Gesuipro08, TAB_CH_ALL%>"
                        HorizontalAlign="right" runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_TPS_PASSE%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_RAF%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_CONSO_PREVUE%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_ECART%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_TX_AV%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_TX_DEP%>" HorizontalAlign="right"
                        runat="server" />
                </asp:TableRow>
            </asp:Table>
            <asp:PlaceHolder ID="phSaisie" runat="server" EnableViewState="false" />
            <asp:Table ID="tblProjet2" Width="100%" runat="server" CellSpacing="0" EnableViewState="true">
                <asp:TableRow ID="trTache2" runat="server" CssClass="EnTete">
                    <asp:TableCell Text="Tâche" Height="20px" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell Width="50" HorizontalAlign="center" runat="server" />
                    <asp:TableCell ID="chAl2" Width="60" CssClass="padL80" Text="<%$ Resources:Gesuipro08, TAB_CH_ALL%>"
                        HorizontalAlign="right" runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_TPS_PASSE%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_RAF%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_CONSO_PREVUE%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_ECART%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_TX_AV%>" HorizontalAlign="right"
                        runat="server" />
                    <asp:TableCell Width="60" Text="<%$ Resources:Gesuipro08, TAB_TX_DEP%>" HorizontalAlign="right"
                        runat="server" />
                </asp:TableRow>
            </asp:Table>
            <table cellspacing="0" style="margin-top: 10px;" width="99.7%">
                <tr class="LigneTotal" id="trTot" runat="server">
                    <td class="LibelleTotal" style="width: 500px; padding-right: 40px;" align="right">
                        <b>TOTAL</b>
                    </td>
                    <td class="tot">
                        <span id="ltlTOT_LUN" runat="server" />
                        <input type="hidden" id="hdnTOT_LUN" />
                    </td>
                    <td class="tot">
                        <span id="ltlTOT_MAR" runat="server" />
                        <input type="hidden" id="hdnTOT_MAR" />
                    </td>
                    <td class="tot">
                        <span id="ltlTOT_MER" runat="server" />
                        <input type="hidden" id="hdnTOT_MER" />
                    </td>
                    <td class="tot">
                        <span id="ltlTOT_JEU" runat="server" />
                        <input type="hidden" id="hdnTOT_JEU" />
                    </td>
                    <td class="tot">
                        <span id="ltlTOT_VEN" runat="server" />
                        <input type="hidden" id="hdnTOT_VEN" />
                    </td>
                    <td align="right">
                        <asp:Table ID="tblSemaine2" runat="server" HorizontalAlign="Right">
                            <asp:TableRow runat="server">
                                <asp:TableCell runat="server" HorizontalAlign="Right" VerticalAlign="Top">
                                    <asp:Button ID="btnPrev2" runat="server" Text=" < " CssClass="bouton" OnClick="btnPrev_Click"
                                        EnableViewState="false" OnPreRender="btnPrevRender" />
                                </asp:TableCell><asp:TableCell runat="server" ID="tdSemaines2">
                                    <asp:DropDownList ID="ddlSemaine2" runat="server" OnPreRender="DdlSemaineLoad" OnSelectedIndexChanged="ddlSemaine2Changed"
                                        EnableViewState="true" AutoPostBack="true" />
                                </asp:TableCell><asp:TableCell runat="server" VerticalAlign="Top">
                                    <asp:Button ID="btnNext2" runat="server" Text=" > " CssClass="bouton" OnClick="btnNext_Click"
                                        EnableViewState="false" OnPreRender="btnNextRender" />
                                </asp:TableCell></asp:TableRow>
                        </asp:Table>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>

以下是代码隐藏:

protected void DdlSemaineLoad(object sender, EventArgs e)
{
    int[] nums = GestionDate.GetNumeroSemaineMois(Convert.ToInt32(hdnMois.Value), Convert.ToInt32(hdnAnnee.Value));

    ddlSemaine.Items.Clear();
    ddlSemaine2.Items.Clear();

    for (int i = 0; i < 6; i++)
    {
        if (nums[i] != -1)
        {
            string libelle = "S." + nums[i] + " du " +
                        GestionDate.GetPremierJourSemaine(nums[i], Convert.ToInt32(hdnMois.Value), Convert.ToInt32(hdnAnnee.Value)).ToString("dd/MM") + " au " +
                        GestionDate.GetDernierJourSemaine(nums[i], Convert.ToInt32(hdnMois.Value), Convert.ToInt32(hdnAnnee.Value)).ToString("dd/MM");
            ddlSemaine.Items.Add(new ListItem(libelle, nums[i].ToString()));
            ddlSemaine2.Items.Add(new ListItem(libelle, nums[i].ToString()));
        }
    }
    ddlSemaine.SelectedValue = hdnSemaine.Value;
    ddlSemaine2.SelectedValue = hdnSemaine.Value;
}


protected void Page_Load(object sender, EventArgs e)
{
    GererDroits();

    ScriptManager.RegisterClientScriptInclude(this, GetType(), "SVA02JS", "../Js/SVA02.js");

    droitsAdmin = ACLManager.GetDroitsEcran("PRO01");

    nbMaxJourSaisieExterne = Convert.ToInt32(ConfigurationManager.AppSettings.Get("nbMaxJourSaisieExterne"));

    if (!this.IsPostBack)
    {
        Session["ChaineIdProjet"] = null;
        Session["ListeIdProjet"] = null;

        if (Session[Resources.Gesuipro08.SESSION_CONTROLE] != null)
        {
            hdnBCTR01.Value = Session[Resources.Gesuipro08.SESSION_CONTROLE].ToString();
        }
        else
        {
            hdnBCTR01.Value = null;
        }

        if (Session[ID_FICHE] != null)
        {
            hdnIdFicheActivite.Value = Session[ID_FICHE].ToString();
            Session[ID_FICHE] = null;

            FicheActivite ficheFiche = ficheActiviteProcess.GetById(Convert.ToInt64(hdnIdFicheActivite.Value));

            if (ficheFiche != null)
            {
                hdnSemaine.Value = GestionDate.GetNumeroPremiereSemaineAvecJoursOuvres(ficheFiche.Mois, ficheFiche.Annee).ToString();
                hdnMois.Value = ficheFiche.Mois.ToString();
                hdnAnnee.Value = ficheFiche.Annee.ToString();

                SaveInfoSession();

                txtRemarque.Text = ficheFiche.CommRessource;

                isFicheValidee = ficheFiche.Valid == FicheActivite.ID_VALIDE;
            }
            else
            {
                Session[Resources.Gesuipro08.SESSION_ERR01] = Resources.Gesuipro08.ERR_No_Fiche;
                Response.Redirect("~/aspx/err01.aspx");
            }
        }
        else
        {
            IList<FicheActivite> lstFiches;

            if (Session[Resources.Gesuipro08.SESSION_CONTROLE_SEMAINE] == null ||
                Session[Resources.Gesuipro08.SESSION_CONTROLE_MOIS] == null ||
                Session[Resources.Gesuipro08.SESSION_CONTROLE_ANNEE] == null)
            {
                hdnSemaine.Value = GestionDate.GetNumeroSemaine(DateTime.Today).ToString();
                hdnMois.Value = DateTime.Now.Month.ToString();
                hdnAnnee.Value = DateTime.Now.Year.ToString();

                SaveInfoSession();
            }
            else
            {
                hdnSemaine.Value = Session[Resources.Gesuipro08.SESSION_CONTROLE_SEMAINE].ToString();
                hdnMois.Value = Session[Resources.Gesuipro08.SESSION_CONTROLE_MOIS].ToString();
                hdnAnnee.Value = Session[Resources.Gesuipro08.SESSION_CONTROLE_ANNEE].ToString();
            }

            lstFiches =
                ficheActiviteProcess.GetFichesActivite(
                    ressource.IdRess,
                    (short)DateTime.Now.Month,
                    (short)DateTime.Now.Month,
                    (short)DateTime.Now.Year,
                    (short)DateTime.Now.Year);

            if (lstFiches != null && lstFiches.Count > 0)
            {
                hdnIdFicheActivite.Value = lstFiches[0].Id.ToString();
                txtRemarque.Text = lstFiches[0].CommRessource;
            }
            else
            {
                FicheActivite newFA = new FicheActivite();

                newFA.Annee = (short)DateTime.Now.Year;
                newFA.Mois = (short)DateTime.Now.Month;
                newFA.IdCollab = ressource.IdRess;
                newFA.DateCreate = DateTime.Today;
                newFA.DateModif = DateTime.Today;
                newFA.UserCreate = AuthenticationManager.GetUtilisateur().Num_User;
                newFA.UserModif = AuthenticationManager.GetUtilisateur().Num_User;

                ficheActiviteProcess.Inserer(newFA);

                lstFiches = ficheActiviteProcess.GetFichesActivite(
                        ressource.IdRess,
                        (short)DateTime.Now.Month,
                        (short)DateTime.Now.Month,
                        (short)DateTime.Now.Year,
                        (short)DateTime.Now.Year);
            }

            if (lstFiches != null && lstFiches.Count > 0)
            {
                hdnIdFicheActivite.Value = lstFiches[0].Id.ToString();
                txtRemarque.Text = lstFiches[0].CommRessource;

                isFicheValidee = lstFiches[0].Valid == FicheActivite.ID_VALIDE;
            }
            else
            {
                Session[Resources.Gesuipro08.SESSION_ERR01] = Resources.Gesuipro08.ERR_No_Fiche;
                Response.Redirect("~/aspx/err01.aspx");
            }
        }

        CreerArborescence(true);
    }

    StringBuilder js = new StringBuilder(1500);
    js.AppendLine("<script type='text/javascript' language='javascript'>");
    js.AppendLine("SVA02.hdnSemaineId='" + hdnSemaine.ClientID + "';");
    js.AppendLine("SVA02.hdnModifId='" + hdnModif.ClientID + "';");
    js.AppendLine("SVA02.lblMsgId='" + lblMessage.ClientID + "';");
    js.AppendLine("SVA02.btnEnregId='" + btnEnreg.ClientID + "';");
    js.AppendLine("SVA02.msgModif='" + Resources.Gesuipro08.SVA02_Msg_Modif + "';");
    js.AppendLine("SVA02.msgExportCra='" + Resources.Gesuipro08.SVA02_Msg_ExportCra + "';");
    js.AppendLine("SVA02.msgEnrTotal=\"" + Resources.Gesuipro08.SVA04_MSG_ENR_TOTAL + "\";");
    js.AppendLine("SVA02.nbMaxJourSaisieExterne='" + nbMaxJourSaisieExterne + "';");
    js.AppendLine("SVA02.msgEnrTotalExt=\"" + string.Format(Resources.Gesuipro08.SVA04_MSG_ENR_TOTAL_EXTERNE, nbMaxJourSaisieExterne) + "\";");
    if (ACLManager.DisposeException(WebConstants.EXCEPTION_COLLAB_EXTERNE))
    {
        js.AppendLine(string.Format("SVA02.calculerTotalExterne($('{0}'), '{1}', '{2}', '{3}', '{4}', '{5}')", Page.Form.ClientID, ltlTOT_LUN.ClientID, "hdnTOT_LUN", idsChampChargeCachee[0], 0, nbMaxJourSaisieExterne));
        js.AppendLine(string.Format("SVA02.calculerTotalExterne($('{0}'), '{1}', '{2}', '{3}', '{4}', '{5}')", Page.Form.ClientID, ltlTOT_MAR.ClientID, "hdnTOT_MAR", idsChampChargeCachee[1], 1, nbMaxJourSaisieExterne));
        js.AppendLine(string.Format("SVA02.calculerTotalExterne($('{0}'), '{1}', '{2}', '{3}', '{4}', '{5}')", Page.Form.ClientID, ltlTOT_MER.ClientID, "hdnTOT_MER", idsChampChargeCachee[2], 2, nbMaxJourSaisieExterne));
        js.AppendLine(string.Format("SVA02.calculerTotalExterne($('{0}'), '{1}', '{2}', '{3}', '{4}', '{5}')", Page.Form.ClientID, ltlTOT_JEU.ClientID, "hdnTOT_JEU", idsChampChargeCachee[3], 3, nbMaxJourSaisieExterne));
        js.AppendLine(string.Format("SVA02.calculerTotalExterne($('{0}'), '{1}', '{2}', '{3}', '{4}', '{5}')", Page.Form.ClientID, ltlTOT_VEN.ClientID, "hdnTOT_VEN", idsChampChargeCachee[4], 4, nbMaxJourSaisieExterne));
    }
    else
    {
        js.AppendLine(string.Format("SVA02.calculerTotalCol($('{0}'), '{1}', '{2}', '{3}', '{4}')", Page.Form.ClientID, ltlTOT_LUN.ClientID, "hdnTOT_LUN", idsChampChargeCachee[0], 0));
        js.AppendLine(string.Format("SVA02.calculerTotalCol($('{0}'), '{1}', '{2}', '{3}', '{4}')", Page.Form.ClientID, ltlTOT_MAR.ClientID, "hdnTOT_MAR", idsChampChargeCachee[1], 1));
        js.AppendLine(string.Format("SVA02.calculerTotalCol($('{0}'), '{1}', '{2}', '{3}', '{4}')", Page.Form.ClientID, ltlTOT_MER.ClientID, "hdnTOT_MER", idsChampChargeCachee[2], 2));
        js.AppendLine(string.Format("SVA02.calculerTotalCol($('{0}'), '{1}', '{2}', '{3}', '{4}')", Page.Form.ClientID, ltlTOT_JEU.ClientID, "hdnTOT_JEU", idsChampChargeCachee[3], 3));
        js.AppendLine(string.Format("SVA02.calculerTotalCol($('{0}'), '{1}', '{2}', '{3}', '{4}')", Page.Form.ClientID, ltlTOT_VEN.ClientID, "hdnTOT_VEN", idsChampChargeCachee[4], 4));
    }
    js.AppendLine("</script>");
    ScriptManager.RegisterStartupScript(this, GetType(), "SVA02_INIT", js.ToString(), false);

    if (ACLManager.DisposeException(WebConstants.EXCEPTION_COLLAB_EXTERNE))
    {
        btnEnreg.OnClientClick = "if(SVA02.RV_ENREG_EXT()) {Chargement(true); return true;} else {return false;}";
    }
    else
    {
        btnEnreg.OnClientClick = "if(SVA02.RV_ENREG()) {Chargement(true); return true;} else {return false;}";
    }

    lnkExportCRA.OnClientClick = "return SVA02.checkBeforCRA();";
    btnPrev.OnClientClick = "return SVA02.checkBeforExit();";
    btnPrev2.OnClientClick = "return SVA02.checkBeforExit();";
    btnNext.OnClientClick = "return SVA02.checkBeforExit();";
    btnNext2.OnClientClick = "return SVA02.checkBeforExit();";
    lnkAfficherSynthese.OnClientClick = "return SVA02.checkBeforExit();";
    btnAjouterExtra.OnClientClick = "return SVA02.checkBeforExit();";

    GererAideEnLigne("#SignetFicheActivite");
}


protected void ddlSemaineChanged(object sender, EventArgs e)
{
    hdnSemaine.Value = ddlSemaine.SelectedValue;

    SaveInfoSession();

    CreerArborescence(true);
}


protected void ddlSemaine2Changed(object sender, EventArgs e)
{
    hdnSemaine.Value = ddlSemaine2.SelectedValue;

    SaveInfoSession();

    CreerArborescence(true);
}

工作的是ddlSemaineddlSemaine2是破碎的。 我已经尝试将ddlSemaine移到ddlSemaine2后面并停止工作。我还尝试在ddlSemaine2旁边移动ddlSemaine,两者都在工作......

要更具体地说明问题,当我第一次使用ddlSemaine2时,它不会触发OnSelectedIndexChanged并加载没有tblProjettblProjet2的网页。但是在这个“空”页面上,如果我重用ddlSemaine2,它可以正常工作并加载正确的内容。最后,如果我再次使用它,它就不起作用。

我认为问题出在Page_Load方法中,但我找不到。

问题是,我需要它是DropDownList,我无法理解发生了什么,所以我想得到一些帮助。

0 个答案:

没有答案