How to make (link)button function as hyperlink?

前端 未结 5 1554
清酒与你
清酒与你 2021-01-17 08:49

How do I use an asp:Button or asp:LinkButton as asp:Hyperlink?

The existing Hyperlink just goes to another section on the same

5条回答
  •  情话喂你
    2021-01-17 09:31

    There is a middle way. If you want a HTML control but you need to access it server side you can simply add the runat="server" attribute:

    Back
    

    You can then alter the href server side using Attributes

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           lnkBack.Attributes.Add("href", url);
        }
    }
    

    resulting in:

    Back
    

提交回复
热议问题