Button Onclick does not work inside form

2019-02-25 23:16发布

Good Day

I am using an ASP.NET webform where I have wrapped the following button inside the form tags:

<form runat="server">

  <button class="btn btn-primary" onclick="window.location='http://google.co.za';">Login</button>

</form>

ISSUE: The problem is that when clicking on the button, it just directs to the current page...does not redirect. However, when I remove the form tags, the button works. If I leave the form tags and I use an anchor tag to relocate, it works as well...It is just the button that is giving me issues.

Why is that?

I am using Twitter bootstrap as well(extra info..)

Thank you

1条回答
老娘就宠你
2楼-- · 2019-02-25 23:25

Add type="button" attribute to your button tag. Without it button works as submit.

查看更多
登录 后发表回答