Search code examples
c#asp.netwebformssweetalertsweetalert2

Can't use sweet alert in page_load in ASP.NET


I am using SweetAlert.js with asp.net webform project. Imported js and css file in to masterpage and showing message on button click example is working fine.

I would like to show message on page_load when data is not loaded. I have tried but get an error:

reference error. "swal is not defined"

How can we fix this, how can we use sweetalert on page_load? Need your opinion.


Solution

  • When swal is not working on page_load:

    swal("something");
    

    Try this and it is nice solution for it. It waits until document is ready and error disappears.

    $(document).ready(function(){swal("something");}); // It works.
    

    I hope it helps who has faced same issue.