Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. What's Problem?

What's Problem?

Scheduled Pinned Locked Moved ASP.NET
helpquestiondatabase
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi! I'm doing a Web page in which Users can post. -In Page_load , I did : If (!Page.IsPostBack) { Load_Data(); } -In button Post Click Event: If !CheckEmptyControl() { ...... //WriteToDB; } Post Successed! But After Post_Click Event if I click Refresh button in Menu bar of IE. The Post_Click event is re-called, and the result is there's two the same data in DB. How can i fix it?

    C M S 3 Replies Last reply
    0
    • A Anonymous

      Hi! I'm doing a Web page in which Users can post. -In Page_load , I did : If (!Page.IsPostBack) { Load_Data(); } -In button Post Click Event: If !CheckEmptyControl() { ...... //WriteToDB; } Post Successed! But After Post_Click Event if I click Refresh button in Menu bar of IE. The Post_Click event is re-called, and the result is there's two the same data in DB. How can i fix it?

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Anonymous wrote: But After Post_Click Event if I click Refresh button in Menu bar of IE. The Post_Click event is re-called, and the result is there's two the same data in DB The reason is that the client browser submits the same information to the server on the refresh as it did to generate the page. When a page request arrives at the server it treats it as if it is the only request it has ever received. ASP.NET uses some clever abstraction to make it look to you and the user that it is one seamless application. However, there are certain instances where the abstraction breaks down. Anonymous wrote: How can i fix it? So, you must make your database interaction check that the record does not already exist. If it does exist then it does nothing, if it doesn't exist then it inserts a new record.


      Do you want to know more? WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and Forums


      Upcoming talk: SELECT UserName, Password FROM Users -- Getting unauthorised access to a SQL Server, and how to prevent it.

      1 Reply Last reply
      0
      • A Anonymous

        Hi! I'm doing a Web page in which Users can post. -In Page_load , I did : If (!Page.IsPostBack) { Load_Data(); } -In button Post Click Event: If !CheckEmptyControl() { ...... //WriteToDB; } Post Successed! But After Post_Click Event if I click Refresh button in Menu bar of IE. The Post_Click event is re-called, and the result is there's two the same data in DB. How can i fix it?

        M Offline
        M Offline
        morphix
        wrote on last edited by
        #3

        Hi, This is actually one of the most common mistakes i see, but dont worry that also meens that the solution is pretty straight forward. The problem... Page_load() is the FIRST event to be triggered. so you have a situation where your code behaves corectly but just not the way you intended. I guess that you want to have some code execute after your button event was triggered. there are a few methods, but i like to use the PreRender event. the PreRender event is the last event to be fired before the HTML is rendered and send to the client. to use: In the InitializeComponent function add: this.PreRender += new System.EventHandler (this.Page_PreRender); and create a private function: private void Page_PreRender(object sender, System.EventArgs e) { Load_Data(); } thats all there is to it.

        1 Reply Last reply
        0
        • A Anonymous

          Hi! I'm doing a Web page in which Users can post. -In Page_load , I did : If (!Page.IsPostBack) { Load_Data(); } -In button Post Click Event: If !CheckEmptyControl() { ...... //WriteToDB; } Post Successed! But After Post_Click Event if I click Refresh button in Menu bar of IE. The Post_Click event is re-called, and the result is there's two the same data in DB. How can i fix it?

          S Offline
          S Offline
          Syed Abdul Khader
          wrote on last edited by
          #4

          When refreshing the page the browser asks whether you want to resend the page again. If we accept, then it sends the data again. It is equivalent to clicking the post button again. What you will do if click the post button with the same data? If you allow it, the refresh is also doing the same thing. Still if you dont want it do a backend check for the uniqueness and simply display a message that the data already present.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups