2015-09-24 2 views
0

Я работаю над asp в C# a У меня проблема с моим меню.Ссылки не открывают мою страницу в моей главной странице contentPlaceHolder, а на новой вкладке

Мое меню на моей главной странице содержит две ссылки (ссылка на Home.aspx и Contact.aspx) и динамический div, содержащий ссылки, сгенерированные с кодом C#, на другие страницы aspx.

Проблема заключается в том, что я нажимаю на классическую ссылку («Домой» или «Контакт») на загрузку страницы в ContentPlaceHolder моей главной страницы, но с помощью динамических ссылок открывается новая вкладка в моем браузере.

Мои две ссылки в MasterPage, которые работают должным образом:

<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 команды.

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 [email protected] 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 [email protected] 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: Если у вас есть лучший способ сделать это меню, я возьму его.

спасибо.

+0

Это поможет, если вы сможете предоставить соответствующие части кода. – johna

+0

Спасибо, я обновил свой пост. –

ответ

0

В функции «DrawLinks» есть строка ...

string target="_Blank"; 

Заменить «Пустой» с «я», и он будет открываться в том же окне или вкладке.

+0

Спасибо, но когда я перехожу к себе, он меняет что-либо, поэтому я удаляю цель, и она работает правильно –

Смежные вопросы