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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:29:04+00:00 2026-05-24T17:29:04+00:00

I have this code and I am trying to run it on a .NET

  • 0

I have this code and I am trying to run it on a .NET platform but it is not working. Does anyone have any idea what is wrong with my code? Thanks. I am using visual studio 2010, and c# programming language.

private void AlertWithConfirmation()
            {
                Response.Write("<script language='javascript'>");
                Response.Write("var x=window.confirm(\"Are you sure you are ok?\")");
                Response.Write("if (x)");
                Response.Write("window.alert(\"Good!\")");
                Response.Write("else");
                Response.Write("window.alert(\"Too bad\")");
                Response.Write("</script>");
            }
  • 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-24T17:29:06+00:00Added an answer on May 24, 2026 at 5:29 pm

    Your code produces this:

    <script language='javascript'>var x=window.confirm("Are you sure you are ok?")if (x)window.alert("Good!")elsewindow.alert("Too bad")</script>
    

    Note the elsewindow identifier that comes from the lack of separator between the commands, which of course does not exist. It will cause an error because the undefined value doesn’t have an alert method.

    Some improvements:

    • Use the type attribute instead of the deprecated langauge attribute.
    • Use semicolons at the end of statements.
    • Use brackets around code blocks (e.g. following if).
    • Use the return value from confirm directly instead of polluting the global namespace with a variable.
    • Write it as a single string instead of a bunch of strings.

    :

    private void AlertWithConfirmation() {
      Response.Write(
        "<script type=\"text/javascript\">" +
        "if (window.confirm('Are you sure you are ok?')) {" +
        "window.alert('Good!');" +
        "} else {" +
        "window.alert('Too bad');" +
        "}" + 
        "</script>"
      );
    }
    

    Note that if you use this within a regular page, it will write the script tag before the doctype tag, which will cause the browser to go into quirks mode, which will most likely mess up your layout. If you want to add scripts to a regular page you should put a PlaceHolder on the page where you can add it, or use the ClientScriptManager.RegisterStartupScript method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code in my ASP.NET application written in C# that is trying
I have this piece of code I'm trying to get to display but no
I am trying to understand what ThreadPool does, I have this .NET example: class
I'm extremely new to JS and have this code that I'm trying to tweak.
I am trying to compare two dates. I have this code which I thought
I have got this code and I am trying to understand the convention followed,
I have this php code, with which I am trying to generate a popup
I am trying to enable mod_deflate. I have Apache 2.0+ and tried this code
All, I am trying to code a Connect4 game. For this, I have created
I'm trying to create a Rails app template I have this block of code

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.