AGuyCalledGerald
AGuyCalledGerald

Reputation: 8150

Code in Markup for a link-href (.Net)

I have an aspx-Page with an anchor-tag. It´s href has to take a parameter of the page, which is a public member.

public int CommissionId
    {
        get
        {
             //..
        }            
    }

I know how to design the link in code-behind, but want to do it in Markup. I tried

<a href='<% String.Format(@"Details.aspx?commissionId=" + CommissionId) %>' runat="server" id="cancelLink" class="button" onclick="this.blur();"><span>Back</span></a>

but the link doesn´t respond.

Upvotes: 1

Views: 794

Answers (2)

gor
gor

Reputation: 11658

Try change <% to <%=. Hope it helps.

Upvotes: 1

Dima Shmidt
Dima Shmidt

Reputation: 905

Use this code:

<a href='<%# String.Format(@"Details.aspx?commissionId=" + CommissionId) %>' runat="server" id="cancelLink" class="button" onclick="this.blur();"><span>Back</span></a>

And then add to codebehind:

protected void Page_Load(object sender, EventArgs e)
    {
        DataBind();
    }

Hope it will help you. Good luck!!

Best regards, Dima.

Upvotes: 1

Related Questions