[英]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. 我在C#中处理ASP,我的菜单有问题。
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. 我的主页上的菜单包含两个链接(链接到Home.aspx和Contact.aspx)和一个动态div,其中包含用c#代码生成的指向其他aspx页面的链接。
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. 问题是当我单击经典链接(“主页”或“联系人”)时,页面加载到我的主页的ContentPlaceHolder中,但是使用动态链接,它将在浏览器中打开一个新选项卡。
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. 我的菜单由执行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. PS:如果您有制作此菜单的最佳方法,我会接受。
Thank you. 谢谢。
In your function 'DrawLinks' there is a line... 在函数“ DrawLinks”中,有一行...
string target="_Blank";
Replace 'Blank' with 'self' and it will open in the same window or tab. 将“空白”替换为“自我”,它将在同一窗口或选项卡中打开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.