0

I have a button click event where I added javascript confirmation box (Yes / No). I want to make when the user click yes the method will run. Here is the sample:

Asp.Net C# Backend:

Response.Write("<script>var confirmdelete=confirm('No chronological event found.Do you want to continue ?');if (confirmdelete) {('<%=ASPxButton_Approve%>').valueof()}</script>");

ASPxButton_Approve = is the button I will trigger

after that it will show yes no confirmation box. I want to make it when the user will click yes below method will run:

approve();

3 Answers 3

1

on button clientclick only you can write

eg.

 <asp:Button ID="btnSubmit" class="btn btn-success waves-effect waves-light" TabIndex="5" ValidationGroup="validate" formnovalidate="formnovalidate" runat="server" Text="Submit" OnClientClick="if (Page_ClientValidate()){ return confirm('Do you want to add task? Click OK to proceed.')}" OnClick="btnSubmit_Click" />
Sign up to request clarification or add additional context in comments.

Comments

0

You could use OnClientClick attribute, in your frontend file put a button like this:

<asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="false" 
CommandName="Delete" CommandArgument="optionalParameterLikeAKey" 
OnCommand="lnkDelete_Command" OnClientClick="return confirm('No 
chronological event found.Do you want to continue ?');" Text="Delete">

And in code behind catch the action command "Delete":

void lnkDelete_Command(Object sender, CommandEventArgs e) {
    //Code to delete -> e.CommandArgument;
}

Alternatively you could use:

<a href="YourPage.aspx?ID=<%#DataBinder.Eval(Container.DataItem, "ID")%>&action=delete" onclick="return confirm('No 
chronological event found.Do you want to continue ?');">Delete</a>

I hope it helps.

Comments

0

I recommend you to make a javascript function and use CustomValidatorin ASP.NET which is a strong ability to handle client side codes.

To create custom validation logic on the client
Create a validation function in ECMAScript (JavaScript, JScript): The following code example illustrates custom client-side validation. An excerpt from the page shows a TextBox control referenced by a CustomValidator control. The validation control calls a client script function named validateLength to make sure that the user has entered at least eight characters into the TextBox control.

A Typical example:

<script type="text/javascript">
   function validateLength(oSrc, args){
   args.IsValid = (args.Value.length >= 8);
}
</script>


The C# code:

<asp:Textbox id="text1" runat="server" text=""></asp:Textbox>
<asp:CustomValidator id="CustomValidator2" runat="server" 
ControlToValidate = "text1"
ErrorMessage = "You must enter at least 8 characters!"
ClientValidationFunction="validateLength" >
</asp:CustomValidator>

For more information go on here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.