简体   繁体   中英

Im using html code and css in c# to design the button and i don't know how to redirect it to another page after clicked it(ASP.net)

I try using href and posbackturl but it doesn't work . I started learning c# since last week so im still weak on it .Can anyone teach me how to solve it ?

<button class="button" style="vertical-align:middle"><span>Add Contact </span></button>

If you want to simply redirect to to the page, then simply you can forward it by just providing the page to href.

<a href="addcontact.aspx" style="vertical-align:middle" role="button">Add Contact</a>

If you simply want to redirect you can use LinkButton.

<asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/addcontact.aspx">Add Contact</asp:LinkButton>

And if you want to perform some functionality on server side, then you may have to use OnClick event to bind with button which will look like this. Web Form

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Add Contact</asp:LinkButton>

C# Server Side

protected void LinkButton1_Click(object sender, EventArgs e)
{
   //Functionaltiy
   Response.Redirect("/addcontact.aspx");
}

I hope this will solve your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM