mimo
mimo

Reputation: 6817

Why any html button cause postback in aspx page?

I have created .aspx page on my SharePoint site and inserted within the page HTML button.

Example

    <PublishingWebControls:editmodepanel PageDisplayMode="Display" runat="server" SuppressTag="True">
...
<button>Click Me!</button>
...
</PublishingWebControls:editmodepanel>

Every time I hit 'Click Me!' the post back occurs. This is not my desired behavior, but I have found a way how to not cause post backs. I added javascript code to onclick property <button onclick='return false;'>Click Me!</button>

My question is, why the post back occurs, even if the button does not contain type="submit" property?

I checked also master page, which contains <form runat="server"> and wraps all the content and there is also no action="page.aspx" property.

Upvotes: 17

Views: 21997

Answers (2)

Aamir
Aamir

Reputation: 821

I know this is an old post. @Dmytro 's post leads in the right direction but is not the exact answer. To prevent the postback you need to make use of the type attribute of the button tag. i.e.

<button type="button">Click Me!</button>

Upvotes: 13

Dmytro
Dmytro

Reputation: 1600

Check this link, http://www.w3schools.com/tags/tag_button.asp There is a note on page, which says, that different browsers can use different default type for button, if you don't specify it by yourself. Seems like your browser uses "submit".

Upvotes: 30

Related Questions