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