Why any html button cause postback in aspx page?

20,096

Solution 1

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".

Solution 2

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>

Share:
20,096
mimo
Author by

mimo

Updated on July 31, 2020

Comments

  • mimo
    mimo almost 4 years

    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.

  • stevenferrer
    stevenferrer about 6 years
    i've been debugging my app for hours and this magically fixed everything! you saved my day pal!