Asp.net require field validator stops click event

qasimidl 106 Reputation points
2023-03-09T14:20:24.5666667+00:00

Hi,

i have designed web part in SharePoint 2019,

problem:

as i place required field validator on text box, so it stops button click event. (asp.net button click event)

as i remove require field validator, button click events works.

Kindly suggest, what to do to solve it, once data is provide so require validator should let button to play its role.

Thanks

Microsoft 365 and Office | SharePoint | Development
Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-03-10T02:02:37.19+00:00

    Hi @qasimidl

    You can refer to following code to stop click event without data filled in text

    function submitform()
    {
        if (!Page_IsValid) {
            return false;
        }
        return sendHPCIMsg();
    }
    
    
    <asp:Button ID="formPost" text="Submit" class="btn btn-default" runat="server" CausesValidation="true" OnClientClick="return submitform();" />
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.