0

I am creating a Sharepoint 2013 app which perform some task on a button click. When i use the control, the app page auto refreshes after few seconds after the click.

<button id="loadButton" title="loadButton" value="loadButton"></button> 

But when i use a button control with input type, it works correctly.

<input type="button" id="loadButton" value="LoadButton"/>

Why does this happen?

  • are you doing this in an aspx-Page? – Gwny Jun 20 '14 at 10:58
1

In order to prevent the <button> from performing POST, all we have to do is to add type='button'

Correct:

<button type="button" id="loadButton" title="loadButton" value="loadButton"></button> 

Wrong:

<button id="loadButton" title="loadButton" value="loadButton"></button> 

This question is essentially the same as this one.

| improve this answer | |
0

your missing the id in the button.

html

<button title="loadButton" value="loadButton"></button> 

should be:

<button id="loadButton" title="loadButton" value="loadButton"></button> 

html button control needs an id!

JS

function sharePointReady() {
    ctx = new SP.ClientContext.get_current();

    $("#loadButton").click(function (event) {
        refreshpage();
        event.preventDefault();
    });
    callme();
}

function callme() {
    //call after button event do your stuff!
}

function refreshpage() {
    // button clicked do your stuff!

    //return nothing! no postback occures!
    return false;
}

html button has builtin auto postback which i think uses submit event. where input needs to be explicitly told to do postback especially when using button in input so does nothing like in your case!

| improve this answer | |
  • Sorry. It was a typo. I have edited my question. – Thomas Mathew Jun 20 '14 at 7:11
  • do you not want it to refresh? what is the button doing and what is the input doing correctly that the button is not? – Ali Jafer Jun 20 '14 at 7:13
  • On button click, text inside <p> changes. But after few second the page auto refreshes if i use the first control. Auto refresh should not happen. – Thomas Mathew Jun 20 '14 at 7:15
  • ahh i get you so you dont want postback! – Ali Jafer Jun 20 '14 at 7:21
  • in your button event i presume its js just return false! – Ali Jafer Jun 20 '14 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.