问题
I am redirecting to Teammember.aspx page with javascript from code behind.
teammember.Attributes.Add("onclick", "window.location.href='TeamMemberDetails.aspx?Id=" + Id + "'" + "&isabout=true");
When coming on TeamMemberDetails.aspx page i have an anchor tag:
<a style="border: 0px none; float: left;" href="TeamMember.aspx">
<img alt="<--" src="Images/ArrowLeft.png" style="display: inline-block; cursor: pointer;border: 0 none;" />
</a>
Now, Depending on Querystring parameter i.e isabout the page must redirect. if isabout=true then it must redirect to Memberlist.aspx page else other.aspx page using HTML Anchor Tag (Conditional Redirect)
回答1:
put runat="server"
attribute and find anchor tag in code behind.
<a id="lnktoRedirect" runat="server">Redirect</a>
Code behind:
if (isabout)
{
lnktoRedirect.HRef = "Memberlist.aspx";
}
else
{
lnktoRedirect.HRef = "other.aspx";
}
来源:https://stackoverflow.com/questions/15675871/how-to-conditional-redirect-using-html-a-tag-depending-on-querystring-value-in