Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Why is the page always reloaded when I hit test button "Click me"?

(0) ShareShare
ReportReport
Posted on by 290

Hello!

I implemented simple webresource where I put the code from the link below. There is a simple button with the on click event which shows some random text.. If I test it in the CRM, it is shown normally. If I test the same thing on the MS Portal, the result is shown for a second but the page is then refreshed after each click and the text disappears. Is there any reason why is such behavior? Is there any way to prevent it?

Thank you!

Link: https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick

BR,

Miha

Portal

1348.Portal.PNG

CRM
4606.CRM.PNG

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Why is the page always reloaded when I hit test button "Click me"?

    Hi Miha ,

    You can stop the event from firing using below code.

    Html

    <button onclick="myFunc(event)"> Remove </button>  

    Javacscript

      function myFunc(event){

          event.preventDefault();

      }

    The preventDefault () method of the Event interface tells the user agent that if the event is not explicitly processed, its default action should not be taken into account as it would normally be. The event continues to propagate as usual, unless one of its listeners calls stopPropagation () or stopImmediatePropagation (), either of which terminates the propagation.

    For more possible ways you can have a look into below url

    stackoverflow.com/.../how-to-prevent-buttons-from-submitting-forms

    Please Feel free to mark the answer as verified if it is useful

    Regards,

    Vignesh.R

  • Suggested answer
    khoait Profile Picture
    khoait 450 on at
    RE: Why is the page always reloaded when I hit test button "Click me"?

    Hi Miha,

    I think the HTML button in a HTML web resource works because it is a static web page, a button click doesn't cause a reload (postback) while the same button used in the portal page which is a dynamic web page (ASP.NET web form) will cause a postback to web server.

    To avoid this try adding "return false;" in the onClick attribute, for example:

    <button onclick="myFunction(); return false;">Click me</button>


  • Suggested answer
    Syed Ibrahim Profile Picture
    Syed Ibrahim 6,257 on at
    RE: Why is the page always reloaded when I hit test button "Click me"?

    That is the same code given with some default values for that button click event. You need to modify according to your scenario. By the way document.getElement is unsupported way for CRM. All the jQuery codes will work on the portal.. If you want any custom button then pls use RibbonWorkBench tool . Pls refer below for any custom buttons for crm

    www.develop1.net/.../ribbonworkbench.aspx.

    Hope this helps.If the suggestion resolved your query .Pls mark it as answered/verified to close the thread.

  • Justinjose Profile Picture
    Justinjose 2,707 on at
    RE: Why is the page always reloaded when I hit test button "Click me"?

    Hi Miha,

    I have tried the code from the link provided. It worked with out refreshing the page and the text doesn't disappear. are you using the exactly same code from the provided link?

    Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans