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. get/set accessors keep resetting

get/set accessors keep resetting

Scheduled Pinned Locked Moved ASP.NET
databasedesignhelpquestion
5 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.
  • G Offline
    G Offline
    Goalie35
    wrote on last edited by
    #1

    I have a dropdown list control on an aspx page that I need to pass the value of to an ascx page that I reference by using get/set. My problem however is after after I "set" the value, it seems to reset itself back to zero when I try to access it again. Here's my code. I'm using 2 pages (index.aspx & testgridcontrol.ascx: index.aspx: ----------------------------------------------------------------------------- protected void Page_Load(object sender, EventArgs e) { TestGridControl tgc = new TestGridControl(); tgc.physicianID = Convert.ToInt16(dropDownListControl.SelectedItem.Value); } Here's my testgridcontrol.ascx page: public partial class TestGridControl : System.Web.UI.UserControl { private Int16 _physicianID; protected override void OnLoad(EventArgs e) { Response.Write(physicianID); } public Int16 physicianID { get { return _physicianID; } set { _physicianID = value; } } ----------------------------------------------------------------------------- When I "set" this value, it's value is 3 however when I get to the line that reads "Response.Write(physicianID);", the value of physicianID is reset to zero. Any idea what I'm doing wrong? Thanks. -Goalie35

    C 1 Reply Last reply
    0
    • G Goalie35

      I have a dropdown list control on an aspx page that I need to pass the value of to an ascx page that I reference by using get/set. My problem however is after after I "set" the value, it seems to reset itself back to zero when I try to access it again. Here's my code. I'm using 2 pages (index.aspx & testgridcontrol.ascx: index.aspx: ----------------------------------------------------------------------------- protected void Page_Load(object sender, EventArgs e) { TestGridControl tgc = new TestGridControl(); tgc.physicianID = Convert.ToInt16(dropDownListControl.SelectedItem.Value); } Here's my testgridcontrol.ascx page: public partial class TestGridControl : System.Web.UI.UserControl { private Int16 _physicianID; protected override void OnLoad(EventArgs e) { Response.Write(physicianID); } public Int16 physicianID { get { return _physicianID; } set { _physicianID = value; } } ----------------------------------------------------------------------------- When I "set" this value, it's value is 3 however when I get to the line that reads "Response.Write(physicianID);", the value of physicianID is reset to zero. Any idea what I'm doing wrong? Thanks. -Goalie35

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I suspect you are bnding the data to the grid every time the page loads. This will reset the value to 0.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      G 1 Reply Last reply
      0
      • C Christian Graus

        I suspect you are bnding the data to the grid every time the page loads. This will reset the value to 0.

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        G Offline
        G Offline
        Goalie35
        wrote on last edited by
        #3

        Hi Christian. Thanks for the response but I don't think that's quite it. When I step through my code line by line, the process goes as follows: -------------------------------------------------------------------- Index.aspx > TestGridControl tgc = new TestGridControl(); Index.aspx > tgc.physicianID = Convert.ToInt16(dropPhysicians.SelectedItem.Value); TestGridControl.ascx > public Int16 physicianID > set { _physicianID = value; } Index.aspx > End of class Masterpagefile.cs > (my code then hits my masterpage) TestGridControl.ascx > protected override void OnLoad(EventArgs e) > Response.Write(physicianID); TestGridControl.ascx > public Int16 physicianID > get { return _physicianID; } ------------------------------------------------------------- By the time I re-enter testgridcontrol.ascx after my code takes a detour through my masterpage file, my _physicianID variable is already reset to zero. I hope this helps shed some light on my issue. Thanks again. -Goalie35

        R 1 Reply Last reply
        0
        • G Goalie35

          Hi Christian. Thanks for the response but I don't think that's quite it. When I step through my code line by line, the process goes as follows: -------------------------------------------------------------------- Index.aspx > TestGridControl tgc = new TestGridControl(); Index.aspx > tgc.physicianID = Convert.ToInt16(dropPhysicians.SelectedItem.Value); TestGridControl.ascx > public Int16 physicianID > set { _physicianID = value; } Index.aspx > End of class Masterpagefile.cs > (my code then hits my masterpage) TestGridControl.ascx > protected override void OnLoad(EventArgs e) > Response.Write(physicianID); TestGridControl.ascx > public Int16 physicianID > get { return _physicianID; } ------------------------------------------------------------- By the time I re-enter testgridcontrol.ascx after my code takes a detour through my masterpage file, my _physicianID variable is already reset to zero. I hope this helps shed some light on my issue. Thanks again. -Goalie35

          R Offline
          R Offline
          randz
          wrote on last edited by
          #4

          Hi Goalie35, I have a naive question for you. I seek to learn too, on this topic. I noticed on the Page_Load of your example, you have instantiated a new TestGridControl object and assigned it a value. But was the new instance added to the page's control collection?

          Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code.

          S 1 Reply Last reply
          0
          • R randz

            Hi Goalie35, I have a naive question for you. I seek to learn too, on this topic. I noticed on the Page_Load of your example, you have instantiated a new TestGridControl object and assigned it a value. But was the new instance added to the page's control collection?

            Remember, your work is not yours alone. Somewhere, there are some codes written by others amongst us that depends on your work. By failing to see that you are part of their ecosystem, you are bound to break their code.

            S Offline
            S Offline
            Sandeep Akhare
            wrote on last edited by
            #5

            Good question :) as he is creating a new instant of usercontrol and i think he would have added one more instant of usercontrol by registering that user control in aspx Expecting the result on added user control

            Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

            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