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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:53:57+00:00 2026-06-07T21:53:57+00:00

I am writing asp.net project in C#. I have a button in a page

  • 0

I am writing asp.net project in C#.

I have a button in a page default.aspx, and I need javascript alert when I click the button and then update page.
I do this by the following way:

protected void Button1_Click(object sender, EventArgs e)  
{  
Response.Write("<script language='javascript'>alert('OK');</script>");
Response.Redirect("default.aspx");
}

But javascript alert doesn’t occur.
So, how to make first appear javascript alert and then update page?

  • 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-07T21:53:59+00:00Added an answer on June 7, 2026 at 9:53 pm

    It is not working because you are calling the Response.Redirect. Anything that happens before this on the current page will be ineffective, because the new page will immediately redirect before the current page is rendered.

    You have a couple of options, but the one I think you want is this…

    protected void Button1_Click(object sender, EventArgs e)
    {
      Response.Write("<script type='text/javascript'>");
      Response.Write("alert('OK');");
      Response.Write("document.location.href='default.aspx';");
      Response.Write("</script>");
    }
    

    The other option is to store the message you want to display in something like a session variable, and then show it on the new page after the redirection – but that is more complicated and requires the updating of the new page as well.

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

Sidebar

Related Questions

I am writing ASP.NET project in C#. The UpdateUserInfo.aspx page consists textboxes and button.
I am writing a learning project in ASP.NET MVC. I have a page Books
I have an external JavaScript in an asp.net 3.5 project. While writing different functions,
I have a multi-project ASP.NET + C# solution. I was planning on writing a
I'm writing am ASP.NET/C# project, it's a simple blog page with commnents. Problem I'm
I have ASP.NET 4 project (not MVC). I need to create url route based
I'm writing a project in c# asp.net mvc3, and I have a helper-class that
I'm currently writing a project in ASP.NET MVC. I have a web project and
While writing an asp.net project i may have this url for testing/debugging http://localhost:1234/ I
I am writing asp.net project in C# and I have a litle problem. I

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.