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 6950487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:05:53+00:00 2026-05-27T14:05:53+00:00

How to stop the page from rendering the .cs code on click of cancel

  • 0

How to stop the page from rendering the .cs code on click of cancel button on javascript confirm box?

I have a button click event and in some IF condition I am asking the user to confirm. Now when the user clicks on OK button, I have to bind the new data in a grid. but if the user clicks on cancel button, it should not refresh the grid with new data.

Question: On click of cancel button on JavaScript confirm box, how can I stop the following code to be executed, or how can I just return/break from JavaScript?

Can anyone please help me out with this? Thanks in advance.

Markup

<asp:Button ID="btnCopy" runat="server" Text="Copy" Enabled="false" OnClick="btnCopy_Click" ValidationGroup="Copy" />

Code

public void btnCopy_Click(object sender, EventArgs e) { 
    if (Convert.ToInt32(hidId.Value) > 0) {
        string scriptString = "<script language='JavaScript'> ";
        scriptString += "if (confirm('Are you sure to proceed?') == false) {return} ";
        scriptString += "</script>";
        Page.RegisterStartupScript("Confirm", scriptString);
        BindDataGrid();
    }
}
  • 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-05-27T14:05:54+00:00Added an answer on May 27, 2026 at 2:05 pm

    You are mixing server and client side code in the same event, it has to be separated:

    Script:

    function Confirm()
    {
        var record=confirm('Are you sure to proceed??');
        if(record == 1)
        {
            return true;
        }
        else if(record == 0)
        {
            return false;
        }
     }
    

    Markup:

    <asp:Button ID="btnCopy" runat="server" Text="Copy" Enabled="false" 
        OnClick="btnCopy_Click" OnClientClick='return Confirm();' ValidationGroup="Copy" />
    

    Code-behind:

    public void btnCopy_Click(object sender, EventArgs e) { 
        if (Convert.ToInt32(hidId.Value) > 0) {      
            BindDataGrid();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Stop default hashtag behavior with jquery I have some jquery code on
I have two pages - a simple HTML code example page from a jQuery
what is the best way to stop my onclick links from causing the page
I want to stop click on any links until the page is loaded. Can
I have a search page where I would like to stop the user entering
How do you stop the designer from auto generating code that sets the value
Here's a modified version of code from page 586 of Starting Out With C++
In PHP I can use the following to stop HTML from rendering, so it
Possible Duplicate: How do I stop a web page from scrolling to the top
I'm looking for a way to stop the middle mouse click from causing the

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.