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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:22:23+00:00 2026-05-22T02:22:23+00:00

IN asp.net when I submit form and refresh it, the data resubmitted again? Is

  • 0

IN asp.net when I submit form and refresh it, the data resubmitted again?
Is there a way in C# to trap the page refresh event on page load??

  • 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-22T02:22:24+00:00Added an answer on May 22, 2026 at 2:22 am

    ASP.NET doesn’t provide a way to do it directly.

    There are a few techniques, on the other hand, to avoid duplicate submission:

    1. Redirect after submission. This is the worst one. Even if it avoids duplicate submission, it is not acceptable in a modern web application from the users point of view.

    2. Track submissions per form, per session. When the user submits a form for the first time, remember this in the session. If another submission happens, try to determine if it must be discarded or not (in some cases, it must not; for example, if I edit my answer on StackOverflow once, I would be able to do it twice if I need to).

    3. Disable submission with JavaScript after the first submission. This avoids in some cases the situation when either the user double-clicks the submission button, or clicks it for the first time, waits and thinks that the form was not submitted, thus clicking for the second time. Of course, don’t rely on this one: JavaScript may be disabled, it will work on double-click but not on F5 refresh, and in all cases the technique is not completely reliable.

    As an illustration, let’s try to implement the second one.

    Let’s say we have a comment box this.textBoxComment which let the users add a new comment on a page of a blog. The submission is done like this:

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (this.IsPostBack)
        {
            string comment = this.ValidateCommentInput(this.textBoxComment.Text);
            if (comment != null)
            {
                this.databaseContext.AddComment(comment);
            }
        }
    }
    

    If the user clicks twice, the comment will be posted twice.

    Now, let’s add some session tracking:

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (this.IsPostBack)
        {
            if (this.Session["commentAdded"] == null)
            {
                string comment = this.ValidateCommentInput(this.textBoxComment.Text);
                if (comment != null)
                {
                    this.databaseContext.AddComment(comment);
                    this.Session.Add("commentAdded", true);
                }
            }
            else
            {
                // TODO: Inform the user that the comment cannot be submitted
                // several times.
            }
        }
    }
    

    In this case, the user will be able to submit a comment only once. Every other comment will be automatically discarded.

    The problem is that the user may want to add comments to several blog posts. We have two possible ways to allow that. The easy one is to reset the session variable on every non-postback request, but this will allow the user to submit a post on one page, load another page, than hit refresh on the first one, thus submitting the comment twice but not being able to add a comment on the second page any longer.

    private void Page_Load(object sender, System.EventArgs e)
    {
        if (this.IsPostBack)
        {
            if (this.Session["commentAdded"] == null)
            {
                string comment = this.ValidateCommentInput(this.textBoxComment.Text);
                if (comment != null)
                {
                    this.databaseContext.AddComment(comment);
                    this.Session.Add("commentAdded", true);
                }
            }
            else
            {
                // TODO: Inform the user that the comment cannot be submitted
                // several times.
            }
        }
        else
        {
            this.Session.Remove("commentAdded");
        }
    }
    

    The more advanced one is to track in session the list of pages where the comment was submitted.

    private void Page_Load(object sender, System.EventArgs e)
    {
        List<string> commentsTrack = this.Session["commentAdded"] as List<string>;
        string blogPostId = this.ValidatePostId(this.Request.QueryString["id"]);
        if (blogPostId != null)
        {
            if (this.IsPostBack)
            {
                this.AddComment(commentsTrack);
            }
            else
            {
                if (commentsTrack != null && commentsTrack.Contains(blogPostId))
                {
                    commentsTrack.Remove(blogPostId);
                }
            }
        }
    }
    
    private void AddComment(List<string> commentsTrack)
    {
        if (commentsTrack == null || !commentsTrack.Contains(blogPostId))
        {
            string comment = this.ValidateCommentInput(this.textBoxComment.Text);
            if (comment != null)
            {
                this.databaseContext.AddComment(comment);
                if (commentsTrack == null)
                {
                    commentsTrack = new List<string>();
                }
    
                commentsTrack.Add(blogPostId);
                this.Session["commentAdded"] = commentsTrack;
            }
        }
        else
        {
            // TODO: Inform the user that the comment cannot be submitted
            // several times.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a form on my ASP.NET web page. There is submit button also. I've
I'm trying to submit form data with jQuery. I'm using ASP.NET WebMatrix. In a
I wrote this on a simple ASP.NET page: jQuery(document).ready(function() { jQuery(form).submit(function() { alert(kikoo); return
When I submit a form to other page in my ASP.NET site, it asks
dear all i want to know how to submit asp.net form data using jquery
How to handle dynamically generated form submit in asp.net mvc? Form is dynamically created
First time using Asp.net-mvc and originally followed the NerdDinner tutorial. My form submit button
I'm having asp.Net barf at me when I submit the a form with a
I have a asp.net web form which will submit information to come as emails.
I have a form within an ASP.NET MVC application and I'm trying to submit

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.