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. Kind of new to Web Development with ASP.Net and was wondering...

Kind of new to Web Development with ASP.Net and was wondering...

Scheduled Pinned Locked Moved ASP.NET
asp-netcsharpwinformshelpquestion
3 Posts 3 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.
  • S Offline
    S Offline
    Stuart Jeffery
    wrote on last edited by
    #1

    Why on earth does every form I create run the Form_Load event when I click a button on the form? Is there something I am missing in the switch from Windows Forms to Web Forms? I feel like a right n00b on this but it is driving me mad to find that everytime it clears the form before trying to run the code. A bit of further explanation... I have a web-form application that dynamically sets itself up depending on who is looking at it. If an item in a list is selected and then a button clicked that should take you to another form, instead we are taken back through the form setup, which of course reloads the data back into the lists and therefore removes the selectedItem references. So if anyone can help me stop my app doing this inane activity I will be grateful.

    M P 2 Replies Last reply
    0
    • S Stuart Jeffery

      Why on earth does every form I create run the Form_Load event when I click a button on the form? Is there something I am missing in the switch from Windows Forms to Web Forms? I feel like a right n00b on this but it is driving me mad to find that everytime it clears the form before trying to run the code. A bit of further explanation... I have a web-form application that dynamically sets itself up depending on who is looking at it. If an item in a list is selected and then a button clicked that should take you to another form, instead we are taken back through the form setup, which of course reloads the data back into the lists and therefore removes the selectedItem references. So if anyone can help me stop my app doing this inane activity I will be grateful.

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      You need to understand that the way Windows executes program is completely different from the way you will see in your Web(ASP.Net) application. The first thing one should write on the wall before starting any web application is that Web is stateless[^](or Google for a better answer). Here [^]is a very good explanation regarding the order of events in ASP.Net page life.

      Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      1 Reply Last reply
      0
      • S Stuart Jeffery

        Why on earth does every form I create run the Form_Load event when I click a button on the form? Is there something I am missing in the switch from Windows Forms to Web Forms? I feel like a right n00b on this but it is driving me mad to find that everytime it clears the form before trying to run the code. A bit of further explanation... I have a web-form application that dynamically sets itself up depending on who is looking at it. If an item in a list is selected and then a button clicked that should take you to another form, instead we are taken back through the form setup, which of course reloads the data back into the lists and therefore removes the selectedItem references. So if anyone can help me stop my app doing this inane activity I will be grateful.

        P Offline
        P Offline
        PJWindsor
        wrote on last edited by
        #3

        By the sounds of it you need to check the isPostBack property of the Page object. This is used to tell if its the first time the page is loaded or its a postback. If its the first time you would want to do things like your dynamic setup of the form i.e. fill in items in a dropdown box or create dynamic controls but you wouldnt want to do this everytime the page loads, otherwise you end up added the same information twice to the page. Look at the Asp.net Page Life Cycle from that you will find that the page load event will run when before the onclick event of the button. See here http://msdn.microsoft.com/en-us/library/ms178472.aspx[^] If you want the button to redirect to another page then you can use Response.redirect("Somepage.aspx") or Server.Transfer("Somepage.asx") Each has its own merits i would depend on what you are trying to achive. Hope that helps Phil

        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