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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:28:02+00:00 2026-05-16T18:28:02+00:00

I have a MessageBox display when submitting a stream read file. However the box

  • 0

I have a MessageBox display when submitting a stream read file. However the box keeps coming up even after clicking okay. When I hold down the Enter key to fly through the boxes, only one field gets added from the file.

Heres my codebehind

if (FileTypeDDL.SelectedValue == "Calendar Dates" && fileName == "calendar_dates.txt")
{
    //Check if full txt has already been uploaded
    SEPTA_DS.CalendarDatesTBLDataTable GetCalendarDates = (SEPTA_DS.CalendarDatesTBLDataTable)cdta.GetDataByCategory(Convert.ToString(Session["Cat"]));
    var category = Convert.ToString(CategoryDDL.SelectedItem);
    var service_id = Convert.ToString(row["service_id"]);
    var date = Convert.ToString(row["date"]);
    var exception_type = Convert.ToString(row["exception_type"]);
    if (GetCalendarDates.Rows.Count < 1)
    {
        int insertData = Convert.ToInt32(cdta.InsertCalendarDates(category, service_id, date, exception_type));
    }
    else
    {
        DialogResult result = MessageBox.Show("This will overwrite the current list. Are you sure you wish to continue?", "Important Message",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Exclamation);
        if (result == DialogResult.Yes)
        {
            int updateData = Convert.ToInt32(cdta.UpdateCalendarDates(category, service_id, date, exception_type, Convert.ToInt32(GetCalendarDates.Rows[0]["CalendarID"])));
        }
        else
        {
            Response.Redirect("~/Import.aspx");
        }
    }
}

I just want the box to appear once and on ‘Yes’ insert the data. Why and how can I accomplish this.

EDIT: I just realized that this code is within a foreach loop and that’s why it’s reoccurring. My new question; How do I only show this MessageBox once?

  • 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-16T18:28:02+00:00Added an answer on May 16, 2026 at 6:28 pm

    As others have noted, you don’t want to use the WinForms MessageBox method in your ASP.NET pages. It “works,” but what is happening is that a messagebox appears on the server. You see the messagebox because you are developing locally, but if this code were pushed out to a production site visitors wouldn’t see anything – the page would just hang, waiting for someone sitting at the web server to click the OK button! 🙂

    To display a messagebox to a user you need to use client-side script. There are two JavaScript functions you should look into:

    • confirm – displays a dialog box with Ok and Cancel options – this is what you probably want.
    • alert – displays a dialog box with a single Ok button.

    I take it you have a button that the user is clicking to kick off this process. Look into using the OnClientClick property of the Button/LinkButton/ImageButton controls. First, try setting it to something like this:

    OnClientClick="return confirm('Are you sure you want to do this?');"
    

    This will display a messagebox with Ok/Cancel options when the user clicks the button. If they click Cancel the messagebox returns false and the postback is stopped. If they click Ok, it goes through.

    Now, your situation is a little more challenging because you only want to show this if some condition holds, namely if GetCalendarDates.Rows.Count >= 1. The tricky part is that you need to set this JavaScript via the OnClientClick property before the postback. So maybe in Page_Load you can programmatically set the button’s OnClientClick property, but only if the condition of interest holds. Something like:

    void Page_Load(...)
    {
        if (GetCalendarDates.Rows.Count >= 1)
            myButton.OnClientClick = "return confirm('...');";
    }
    

    I’m not sure how or when GetCalendarDates is being set, but you may be best to have the above logic appear whenever GetCalendarDates is set. I presume this is a GridView? If so, consider adding it to the GridView’s DataBound event handler.

    Happy Programming!

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

Sidebar

Related Questions

I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have an MDI application. When I show a message box using MessageBox.Show(), the
I have been using win32api.MessageBox to do alerts, and this works for apps running
I have been trying to implement Win32's MessageBox using GTK. The app uses SDL/OpenGL,
I have the following unmanaged C++ code: MessageBox( NULL, strMessage, Cool Product, MB_RETRYCANCEL |
I have a simple message box in a WPF application that is launched as
I have a status message box (div box) positioned at the bottom of a
I have a Perl script that pops up a message box when its work
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could

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.