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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:38:22+00:00 2026-06-14T14:38:22+00:00

which method is better to prevent re-insertion of data into database after refreshing the

  • 0

which method is better to prevent re-insertion of data into database after refreshing the page ?

should I check the database everytime I insert a row or using the viewState and session is more efficient?

 protected void Page_Load(object sender, EventArgs e)
    {

        /* check refresh */
        if (IsPostBack == false)
        {
            Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
        }
        //rest of the codes
     }

    protected void Page_PreRender(object sender, EventArgs e)
    {
        // set both session and viewstate value equal 
        ViewState["CheckRefresh"] = Session["CheckRefresh"];
    }

    protected void btnSaveTazkera_Click(object sender, EventArgs e)
    {
        if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
        {
            //give a new value to session
            Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
    //rest of the code
    }

tnx.

  • 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-14T14:38:23+00:00Added an answer on June 14, 2026 at 2:38 pm

    Using the session is more effective, but also may not be 100% safe (what if I don’t refresh the page, but re-open the browser and enter the same information again? Session is new and data will still be inserted twice).

    If you want to prevent double insertion of records into the database, the easiest way is to create a respective primary key or do the insertion via a stored procedure that checks whether inserting is OK or not.

    You can still use the session as an additional check before inserting, but the final check should be left to the database/the code that inserts into the database.

    But this is only my opinion and how I’d do it. I don’t think there’s anything like a standard thing to do 🙂

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

Sidebar

Related Questions

Does anyone have any advice on which method is better when caching data in
With .NET, which data access method is better to use LINQ to SQL,entity framework,
Which method is better and why, when? In terms of scalability,performance etc which one
Possible Duplicate: C++ STL: Which method of iteration over a STL container is better?
Which method should I override to be guaranteed to always get the correct size
Which method it is called on 3.ToString()? System.Int16.ToString() System.Int32.ToString() System.Int64.ToString()
Which method is preferred for adding a row to a table? var tr =
Which method is very effective and simple to code to attain this functionality ?
Which method can be used to read one line at a time from a
Which method is preferred to just show 2 links vertically, one over another? in

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.