繁体   English   中英

链接不会在我的母版的contentPlaceHolder中打开我的页面,而是在一个新选项卡中

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

我在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:如果您有制作此菜单的最佳方法,我会接受。

谢谢。

在函数“ DrawLinks”中,有一行...

string target="_Blank";

将“空白”替换为“自我”,它将在同一窗口或选项卡中打开。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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