简体   繁体   中英

Links does not open my page in my masterpage's contentPlaceHolder but in a new tab

I work on a asp in c# an I have problem with my menu.

My menu in my masterpage contains two links (link to Home.aspx and Contact.aspx) and a dynamic div which contains links generated with c# code to different other aspx pages.

The problem is when I click on the classic link (Home or contact) the page load in my masterpage's ContentPlaceHolder, but with the dynamic links it opens a new tab in my browser.

My two links in masterpage which work properly:

<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>

My menu is generated by two functions that execute 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: If you have a best way to make this menu, I will take it.

Thank you.

In your function 'DrawLinks' there is a line...

string target="_Blank";

Replace 'Blank' with 'self' and it will open in the same window or tab.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM