How to conditional Redirect using HTML <a> tag depending on QueryString Value in asp.net?

萝らか妹 提交于 2019-12-13 06:14:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!