I have a file path from a database (~/Dashboard/YearbookRepository/SY2122A/SY 2019-2020.pdf). I bind it in the DataList control using a hyperlink control.
How can I call the hyperlink from code behind using a button?
Below is my aspx file
VB.NET
' CssClass="btn btn-primary font"
Width="190px" Height="100px" UseSubmitBehavior="False" CommandName="Selected" OnClick="btnSelect_Click"/>
' Visible="false">Below is my code behind
C#
protected void btnSelect_Click(object sender, EventArgs e)
{
DataListItem item = (DataListItem)(sender as Button).NamingContainer;
HyperLink hlYearbook = item.FindControl("hlYearbook") as HyperLink;
string url = hlYearbook.Text;
hlYearbook.NavigateUrl = url;
hlYearbook.Target = "_blank";
}If I click the button, the hyperlink does not work. Thank you in advance.


Sachin SinghRank #66 · 26.2K reputationPosted Feb 15, 2022, 4:34 AM EST
Jes SieRank #1,285 · 1.3K reputationPosted Feb 20, 2022, 10:19 PM EST
Sachin SinghRank #66 · 26.2K reputationPosted Feb 20, 2022, 11:53 PM EST
Rijwan AnsariRank #82 · 24.2K reputationPosted Feb 21, 2022, 10:19 AM EST