I have a content placeholder containing a link:
<asp:Content ID="Content5" runat="server" contentplaceholderid="ContentPlaceHolder3">
<a href= "../WOPages/WO_Main.aspx?WONum=12345">WorkOrder</a>
and I would like to change the href querystring from code. How do I find it to change it?
If you add an id
and a runat="server"
attribute to your link...
<a id="YourLink" runat="server" href="../WOPages/WO_Main.aspx?WONum=12345">
WorkOrder
</a>
...then you can access/change the HRef
property programmatically...
YourLink.HRef = "http://stackoverflow.com/";
You could clear all controls from the ContentPlaceholder and then add a new hyperlink control like this:
// Create your hyperlink control
HyperLink lnk = new HyperLink();
lnk.NavigateUrl = "http://domain.com";
lnk.Text = "Click here";
ContentPlaceHolder3.Controls.Clear();
ContentPlaceHolder3.Controls.Add(lnk);
or give the hyperlink an Id and update the hyperlink by finding the control in the ContentPlaceholder:
HyperLink lnk = ContentPlaceHolder3.FindControl("MyLink") as HyperLink;
lnk.NavigateUrl = "http://domain.com/update/";
lnk.Text = "Click here too";
You could use render tags or do this:
<a href="<asp:literal id="hrefString" runat="server"></asp:literal>"
and assign the literal in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With