John Doe
John Doe

Reputation: 2060

ASP button not working

So I am trying to insert a button in my company's sharepoint site with asp. The button appears correctly, but I can't get it to go to a certain page when I click it. When I click it it just refreshes the page. I want it to go to this link... http://www.w3schools.com/ . Can someone help me fix this?

    <WebPartPages:WikiContentWebpart frametype="none" chrometype="None" runat="server" partorder="1" __WebPartId="{9852E1FB-0E97-47D1-BC63-0A8D2D953F9D}" id="g_9852e1fb_0e97_47d1_bc63_0a8d2d953f9d">
        <content>
        <div>
            &nbsp;
            <asp:Button runat="server" Text="Add New Item" id="Button1" Font-Bold="True" onclick="window.location='http://www.w3schools.com/'"></asp:Button> </div>
        </content>
    </WebPartPages:WikiContentWebpart>

Upvotes: 2

Views: 1038

Answers (1)

jrummell
jrummell

Reputation: 43067

<asp:Button runat="server" Text="Add New Item" id="Button1" Font-Bold="True"
     OnClientClick="window.location='http://www.w3schools.com/'; return false;">   </asp:Button>

You need to change two things:

  1. Since this is a client side handler, use OnClientClick.
  2. Return false after setting the location so that the default event (post back) is not fired.

Upvotes: 2

Related Questions