Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:06:38+00:00 2026-06-17T07:06:38+00:00

I have a button on my asp.net site which activates javascript through OnClientClick property

  • 0

I have a button on my asp.net site which activates javascript through OnClientClick property which is set to potwierdzenie().
The script:

<script type="text/javascript"> 
    function potwierdzenie() 
    {
        var answer = confirm("Do you want to delete it")
        if (answer)
            ???
        else
            ???
    }
</script>

All I want to do is do some work (deleting something from mysql db) in c# depending on what user clicked (yes or cancel). How can I do this? How can I execute c# code in this script or how can I do it the other easiest way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:06:39+00:00Added an answer on June 17, 2026 at 7:06 am

    Just return true or false from this callback:

    <script type="text/javascript"> 
        function potwierdzenie() {
            return confirm("Do you want to delete it")
    </script>
    

    Now if the user selects Yes, true will be returned. And if true is returned ASP.NET will execute the OnClick server side callback to which you have subscribed and perform the actual action:

    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        // perform the actual delete here
    }
    

    If the user selects No, false will be returned and the server side callback will never be called.

    It’s important though that in your OnClientClick subscription you do this:

    OnClientClick="return potwierdzenie()"
    

    And here’s a full example of how your link might look like:

    <asp:Button 
        ID="btnDelete" 
        runat="server" 
        OnClientClick="return potwierdzenie()" 
        OnClick="BtnDelete_Click" 
        Text="Delete record"
    />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my ASP.Net Web Site I have a button.When I click the button and
I use ASP.NET and have a Button and a CustomValidator, which has to validate
I have an ASP.NET button in my application, which I want to open another
I have a asp.net webform with a button. The OnClientClick event is wired to
I have an ASP.NET form (C#) but which I click this button that should
I have asp.net web site in which user can login and also do logout
I have a very simple application which consists of an ASP.NET front end site,
I have for example ASP.NET site with textbox, button and many other controls. When
I am currently writing a ContentManager in ASP.NET. I have a preview button which
I have a form in an ASP.NET MVC site which the user can edit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.