简体   繁体   中英

SweetAlert prompt with ASP.NET webforms

I can seem to figure out how to replace the default JS prompt with SweetAlert's prompt and assign the value returned by the prompt to a hidden field like I'm currently doing(in the code below) with OnClientClick="HiddenField1.value = defaultval()"

<script language='javascript'>
    function defaultval() {
        var pmt = prompt('Please enter a name for the template.',
            document.getElementById('HiddenFieldCurrentTemplate').value);
        return pmt;
    }
</script>

<asp:Button ID="btnSaveTemplate" runat="server" CssClass="btn-primary"  OnClientClick="HiddenField1.value = defaultval()" Text="Save as Template" />

Modified from the SweetAlert documentation here:

https://sweetalert.js.org/guides/#using-dom-nodes-as-content

swal("Please enter a name for the template.", {
  content: "input",
})
.then((response) => {
  document.getElementById('HiddenFieldCurrentTemplate').value = response;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM