Anchor Link not redirecting when generating dynamic HTML in ASP.Net

Last Reply one year ago By pandeyism

Posted one year ago

Hello I have taken asp:litral control and bound text from code behind.

In my design there is anchor tag and for that i have dynamicaly bounded href but its not working what to do?


My front end code is :

<div class="timeline-blog overflow padding-top">
    <div class="timeline-divider overflow padding-bottom">
        <asp:Literal runat="server" ID="Lsocialactivities"></asp:Literal> 

and my back end code is :

        protected void showsocialevents()
            SqlCommand cmd = new SqlCommand("Select * from SocialActivity order by SubmitDate DESC", con);
            SqlDataReader sdr = cmd.ExecuteReader();
            if (sdr.HasRows)
                while (sdr.Read())
                    DateTime dt = DateTime.Parse(sdr.GetValue(4).ToString());
                    string strdt = dt.ToShortDateString();
                    Lsocialactivities.Text += "<div class='col-sm-6 padding-right arrow-right wow fadeInLeft'  style='margin-top:30px' data-wow-duration='1000ms' data-wow-delay='300ms'><div class='single-blog timeline'><div class='single-blog-wrapper'><div class='post-thumb'><img src='" + sdr.GetValue(2).ToString() + "' class='img-responsive'><div class='post-overlay'><span class='uppercase'><a hef='ActivityDetails.aspx?aid=" + sdr.GetValue(0).ToString() + "' ><small> " + strdt + "</small></a></span></div></div></div><div class='post-content overflow'><h2 class='post-title bold' style='font-family: Poppins;'><a hef='ActivityDetails.aspx?aid=" + sdr.GetValue(0).ToString() + "'>" + sdr.GetValue(1).ToString() + "</a></h2><p style='font-family: Poppins;'>" + sdr.GetValue(3).ToString() + "</p><a Class='btn btn-common' hef='ActivityDetails.aspx?aid=" + sdr.GetValue(0).ToString() + "'>View More</a><div class='post-bottom overflow'><span class='post-date pull-left'>" + strdt + "</span></div></div></div></div>";

this href is not working -

<a Class='btn btn-common' hef='ActivityDetails.aspx?aid=" + sdr.GetValue(0).ToString() + "'>View More</a>
Posted one year ago
ashishk says:
<a hef='ActivityDetails.aspx?aid

 Anchor tag has href property not hef.

So you need to change hef with href.