Search code examples
javascriptgenexus

User control buttons actions


I have this user control:

function Test1($)
{
    this.Width;
    this.Height;

    this.show = function()
    {
        ///UserCodeRegionStart:[show] (do not remove this comment.)
        var buffer = "..." +
                    "<button onclick=\"alertfuncfora()\"> click </button>" + 
                    "...";

        this.setHtml(buffer);

        ...

        ///UserCodeRegionEnd: (do not remove this comment.)
    }
    ///UserCodeRegionStart:[User Functions] (do not remove this comment.)

    ///UserCodeRegionEnd: (do not remove this comment.):
}

...

function alertfuncfora(){
    alert("ola ola");
}

But every time the button is clicked the page is refreshed after I close the pop up window. I don't want to refresh the page every time I click in a button. How do I do this?


Solution

  • This happens because your button is probably inside a <form> tag.

    Use return false; to prevent the refresh.

    Something like this:

    <button onclick="alertfuncfora(); return false;"> click </button>