C#C
C#2y ago
Whiteboy

✅ Submit form just once, disabling the button breaks form submition

So i need to submit form just once and the submitions takes about 3-5s, how can i prevent user from spamming the button (it creates huge load on server if he spams 100cps)

if i wrote simple JS to disable the button after clicking it doesn't submit the form

    <form method="post" asp-page-handler="SubmitCode" asp-route-assignmentId="@Model.Assignment.AssignmentId">
        <div align="center">
            <textarea id="UserCode" name="UserCode" class="form-control" style="resize: vertical; width: 98%;" rows="20" placeholder="Enter your code here"></textarea>
        </div>
        <div style="margin-right: 1%; margin-bottom: 1%; margin-top: 1%" align="right">
            <button id="SubmitCode" type="submit" name="action" value="SubmitCode" class="btn btn-primary" disabled>Submit</button>
        </div>
    </form>
Was this page helpful?