Advise on how to reuse code behind in asp.net VB pages
-
Hallo I have about 100 asp.net forms. I have a master page and many pages that refer to the master. The .aspx pages differ, but the .aspx.vb codebehind of all is essentially identical. The .aspx_vb has some parameter declarations and constants at the top, but the remainder of the .aspx_vb is identical generalised code - handling events like page_init, page_load etc. Obviously this is inefficient to maintain. Can someone offer advice of what techniques I should investigate to be able to centralise the common code into one code base and maintain it once. I have written extensions to existing controls previously - for example I have written extensions that inherit GridView and DropDownList. I also use User Controls extensively. Can someone point me to examples or articles to assist me solve this problem? thanks, Grant
-
Hallo I have about 100 asp.net forms. I have a master page and many pages that refer to the master. The .aspx pages differ, but the .aspx.vb codebehind of all is essentially identical. The .aspx_vb has some parameter declarations and constants at the top, but the remainder of the .aspx_vb is identical generalised code - handling events like page_init, page_load etc. Obviously this is inefficient to maintain. Can someone offer advice of what techniques I should investigate to be able to centralise the common code into one code base and maintain it once. I have written extensions to existing controls previously - for example I have written extensions that inherit GridView and DropDownList. I also use User Controls extensively. Can someone point me to examples or articles to assist me solve this problem? thanks, Grant
You can use Classes that are essential in object-oriented programming. These will have functions that you can call to in any of your pages. I found numerous tutorials by searching writing and using classes in aspx[^]
-
Hallo I have about 100 asp.net forms. I have a master page and many pages that refer to the master. The .aspx pages differ, but the .aspx.vb codebehind of all is essentially identical. The .aspx_vb has some parameter declarations and constants at the top, but the remainder of the .aspx_vb is identical generalised code - handling events like page_init, page_load etc. Obviously this is inefficient to maintain. Can someone offer advice of what techniques I should investigate to be able to centralise the common code into one code base and maintain it once. I have written extensions to existing controls previously - for example I have written extensions that inherit GridView and DropDownList. I also use User Controls extensively. Can someone point me to examples or articles to assist me solve this problem? thanks, Grant
The "easiest" way (IMO) to get some reuse is to identify methods that can be made static; with ease; i.e. don't have dependencies that can't be easily made into "parms". Those can be put in a static class / dll and shared that way. I have a lot of "builders" and "adapters" in that category.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
-
You can use Classes that are essential in object-oriented programming. These will have functions that you can call to in any of your pages. I found numerous tutorials by searching writing and using classes in aspx[^]
Thanks Andre
-
The "easiest" way (IMO) to get some reuse is to identify methods that can be made static; with ease; i.e. don't have dependencies that can't be easily made into "parms". Those can be put in a static class / dll and shared that way. I have a lot of "builders" and "adapters" in that category.
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Thanks Gerry. Helpful to know that there is no silver bullet. Based on this advice I'm isolating some functions out, and also building a class that inherits from the base.
-
Thanks Andre
You're welcome.