Dear all,
I am trying to create a functionality,which will display tag's name as hyperlinks, within the content of the article.
I have attempted to create a onPreRender method, which computes the above task. However, the code below, is failing to output tag names, as hyperlinks, in the article content, on the client-side.
protected override void OnPreRender(EventArgs e)
{
var ctrl = new HtmlGenericControl("div");
string html = this.GetArticleText();
string link = this.CreateLinkHtml();
string tags = this.LoadAllTags();
html.Replace(tags, link);
ctrl.InnerHtml = html;
this.txtDescription.Controls.Add(ctrl);
base.OnPreRender(e);
}
GetSArticleText(), CreateLinkHTML() and LoadAllTags(), are method which return a string, as an output. I am little unsure, where I may be going wrong and when debugging the code, what parameter should i be looking for?
GetSArticleText(), CreateLinkHTML() and LoadAllTags()
Methods:
public string CreateLinkHtml()
{
string tag = "";
tag = @"###########";
return tag;
}
-----------------------------------------
public string GetArticleText()
{
string htmlStr = "";
string strConnectionString = ConfigurationManager.ConnectionStrings["######"].ConnectionString;
SqlConnection thisConnection = new SqlConnection(strConnectionString);
SqlCommand thisCommand = thisConnection.CreateCommand();
thisCommand.CommandText = "SELECT top 1 title, body from [article] order by UploadDate desc";
thisConnection.Open();
SqlDataReader reader = thisCommand.ExecuteReader();
while (reader.Read())
{
string Name = reader.GetString(0);
string Pass = reader.GetString(1);
Pass = Pass.Replace("<p>", "");
Pass = Pass.Replace("<p>", "");
Pass = Pass.Replace("</p>", "");
htmlStr += "<tr><h2>" + Name + "</h2></tr><tr>" + Pass + "</tr>";
}
thisConnection.Close();
return htmlStr;
}
-------------------------------------------
public string LoadAllTags()
{
string table = "";
try
{
string tag = "";=
string strConnectionString = ConfigurationManager.ConnectionStrings["#######"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
string strCommandText = "select [fullname] from [dbo].[tag_Library]";
SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
cmd.Parameters.AddWithValue("fullname", tag);
myConnect.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
string result = reader.GetString(0);
table += "<tr>" + result + "</tr>";
}
myConnect.Close();
}
catch (Exception ex)
{
throw ex;
}
return table;
}
Client-side HTML code:
<asp:TextBox
ID="txtDescription"
runat="server"
TextMode="MultiLine"
Height="150px"
OnClientClick= "tinyMCE.triggerSave(false,true);"
Width="400px"></asp:TextBox>
<br />
<table width="100%" align="center" cellpadding="2" cellspacing="2" border="0" >
<%=GetArticleText()%>
</table>
htmlStr += "<tr><td><h2>" + Name + "</h2></td></tr><tr><td>" + Pass + "</td></tr>";
Please advice, if possible.
Thank you