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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. ASP.NET v.2 code behind

ASP.NET v.2 code behind

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelpquestion
4 Posts 2 Posters 1 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.
  • G Offline
    G Offline
    Gary Hyslop at home
    wrote on last edited by
    #1

    After converting my first ASP.NET 1.1 project to 2.0, I discovered that one of my button's onclick handler wasn't working. I then proceeded to inspect the InitializeComponent code to find that it was empty. Also there was no declartion of the button control -- or any other control present. Where does ASP.NET v2.0 put this code? Also, is there any way of fixing my problem in code or do I have to delete the button and re-create it so that ASP.NET v2.0 can do it's "under the hood" stuff right? JSaybrook

    B 1 Reply Last reply
    0
    • G Gary Hyslop at home

      After converting my first ASP.NET 1.1 project to 2.0, I discovered that one of my button's onclick handler wasn't working. I then proceeded to inspect the InitializeComponent code to find that it was empty. Also there was no declartion of the button control -- or any other control present. Where does ASP.NET v2.0 put this code? Also, is there any way of fixing my problem in code or do I have to delete the button and re-create it so that ASP.NET v2.0 can do it's "under the hood" stuff right? JSaybrook

      B Offline
      B Offline
      Brent Lamborn
      wrote on last edited by
      #2

      The reason this works has to do with the partial keyword applied to your codebehind class. In addition to turning your .aspx file into a class definition with methods for rendering the page, as it has always done, ASP.NET now also generates a sibling partial class for your codebehind class that contains protected control member variable declarations. Your class is then compiled together with this generated class definition and used as the base class for the class generated for the .aspx file. The end result is that you essentially write codebehind classes the way you always have, but you no longer have to declare (or let the designer declare for you) member variable declarations of server-side controls.

      "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine. M y and h don't work so well due to m addiction to caffeine and m in abilit to to set a cup down uprigt.

      G 1 Reply Last reply
      0
      • B Brent Lamborn

        The reason this works has to do with the partial keyword applied to your codebehind class. In addition to turning your .aspx file into a class definition with methods for rendering the page, as it has always done, ASP.NET now also generates a sibling partial class for your codebehind class that contains protected control member variable declarations. Your class is then compiled together with this generated class definition and used as the base class for the class generated for the .aspx file. The end result is that you essentially write codebehind classes the way you always have, but you no longer have to declare (or let the designer declare for you) member variable declarations of server-side controls.

        "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine. M y and h don't work so well due to m addiction to caffeine and m in abilit to to set a cup down uprigt.

        G Offline
        G Offline
        Gary Hyslop at home
        wrote on last edited by
        #3

        My basic problem is that one of my buttons, that used to work in the 1.1 version no longer works after the application was converted to 2.0. By that I mean that that the OnClick event doesn't fire. In 1.1 the probable culprit would be a missing "wireup" in InitializeComponent. Now the only reference to the button control that I control appears to be the one in the "html" in the aspx page. Would it help to delete this reference and re-create it? According to what you say it wouldn't appear to matter whether I used an editor or the designer to do this. jsaybrook

        B 1 Reply Last reply
        0
        • G Gary Hyslop at home

          My basic problem is that one of my buttons, that used to work in the 1.1 version no longer works after the application was converted to 2.0. By that I mean that that the OnClick event doesn't fire. In 1.1 the probable culprit would be a missing "wireup" in InitializeComponent. Now the only reference to the button control that I control appears to be the one in the "html" in the aspx page. Would it help to delete this reference and re-create it? According to what you say it wouldn't appear to matter whether I used an editor or the designer to do this. jsaybrook

          B Offline
          B Offline
          Brent Lamborn
          wrote on last edited by
          #4

          Are you using the CodeFile keyword in your @Page directive? What about runat="server" in the button? (Just making sure)

          "Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine. M y and h don't work so well due to m addiction to caffeine and m in abilit to to set a cup down uprigt.

          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