链接无法在我的母版页的contentPlaceHolder中打开我的页面,但在新标签

时间:2015-09-24 13:24:06

标签: c# asp.net menu tabs master-pages

我在c#中使用asp工作,我的菜单有问题。

我的主页中的我的菜单包含两个链接(指向Home.aspx和Contact.aspx的链接) 和一个动态div,它包含用c#代码生成的链接到不同的其他aspx页面。

问题是当我在我的母版页的ContentPlaceHolder中点击经典链接(主页或联系人)页面加载时,但是通过动态链接,它会在我的浏览器中打开一个新选项卡。

我在母版页中的两个链接正常工作:

<a id="backHome\" href="Accueil.aspx">Accueil</a>
                    <br/>
                    <br/>
                    <a id="toutDev" href="Accueil.aspx">Tout développer</a> - <a id="toutRed" href="Contact.aspx">Tout réduire</a>

我的菜单由两个执行SQL Command的函数生成。

  Dictionary <string,string> DrawChilds(int idCategorieMere)
    {
        Dictionary<string, string> dictRep = new Dictionary<string, string>();
        SqlCommand requete = new SqlCommand();
        requete.Connection = connectionToDB;

        requete.CommandType = System.Data.CommandType.Text;
        string strReq = @"SELECT distinct Web_Categories.IDCategorie, Nom";
        strReq += " FROM Web_Categories inner join Web_Profil_Joint_Categories on Web_Categories.IDCategorie = Web_Profil_Joint_Categories.IDCategorie";
        strReq += " WHERE IDCategorieMere=@idCategoryMere AND Web_Profil_Joint_Categories.IDProfil in ({0})";
        strReq += " ORDER BY Nom ASC";
        requete.Parameters.AddWithValue("@idCategoryMere", idCategorieMere);


        string inClause = string.Join(",", userConnected.arraylistForSQL);

        requete.CommandText = string.Format(strReq, inClause);

        for (int i = 0; i < userConnected.arraylistForSQL.Length; i++)
        {
            requete.Parameters.AddWithValue(userConnected.arraylistForSQL[i], userConnected.idsProfil[i]);
        }

        using (SqlDataReader reader = requete.ExecuteReader())
        {
            while (reader.Read())
            {
                dictRep.Add(reader[0].ToString(),reader[1].ToString());
            }
        }
        return dictRep;
    }


  void DrawLinks(int idCategorie, int idDiv ,int offset)
    {
        string image;
         SqlCommand requete = new SqlCommand();
        requete.Connection = connectionToDB;

        requete.CommandType = System.Data.CommandType.Text;
        string strReq = @"SELECT distinct NomDocument, Lien, Type";
        strReq += " FROM Web_Documents inner join Web_Profil_Joint_Documents on Web_Documents.IDDocument = Web_Profil_Joint_Documents.IDDocument";
        strReq += "  WHERE IDCategorie=@idCat AND Web_Profil_Joint_Documents.IDProfil in ({0})";
        strReq += " ORDER BY NomDocument asc";
        requete.Parameters.AddWithValue("idCat",idCategorie);
        string inClause = string.Join(",", userConnected.arraylistForSQL);

        requete.CommandText = string.Format(strReq, inClause);

        for (int i = 0; i < userConnected.arraylistForSQL.Length; i++)
        {
            requete.Parameters.AddWithValue(userConnected.arraylistForSQL[i], userConnected.idsProfil[i]);
        }

        using (SqlDataReader reader = requete.ExecuteReader())
        {
            int index=1;
            string target="_Blank";

            while (reader.Read())
            {
                string path="RacineSite"+reader["Lien"].ToString().Replace(".asp", ".aspx");

                if (reader.FieldCount == 1)
                {
                   image = "../images/" + reader["Type"] + ".gif";
                }
                else
                {
                   image = "../images/" + reader["Type"] + "join.gif";
                }

                menuExpl.AppendLine("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>");
                menuExpl.AppendFormat("<td width=\"{0}\" valign=middle nowrap></td>", offset - 2);
                menuExpl.AppendLine("<td><img border=\"0\" src=\"{0}\" width=\"30\" height=\"15\"></td>");
                menuExpl.AppendLine("<td width=\"5\" valign=middle nowrap></td><td>");
                menuExpl.AppendLine("<a onmouseout=\"this.style.textDecorationUnderline=false\" ");
                menuExpl.AppendLine("onmouseover=\"this.style.textDecorationUnderline=true;this.style.cursor=\'hand\'\"");
                menuExpl.AppendFormat("href=\"{0}\" target=\"{1}\">",path,target);
                menuExpl.AppendFormat("<font id=\"{0}-{1}doc\" size=\"-1\">{2}</font>",idCategorie,index,reader["NomDocument"]);
                menuExpl.AppendLine("</a></td></tr></table>");
                index++;
            }
        }

    }

PS:如果你有最好的方法来制作这个菜单,我会接受它。

谢谢。

1 个答案:

答案 0 :(得分:0)

在您的功能&#39; DrawLinks&#39;有一条线......

C

替换&#39;空白&#39;与自我&#39;它将在同一个窗口或标签中打开。