Introduction
Have you ever found yourself writing the same piece of code again and again on a highly costomized page? For example, on a page with a master record control and many detail table controls, you need to access a field in the master record from the detail tables. This is what the code snippet may look like,Even though the repeated code is just two lines, it could be a maintenance headache. If the field is renamed, or its control type is switched from TextBox to DropDownList, there will be multiple places to be modified.
Here is the tip: Put the code snippet in a page extension method, so that it can be reused.
Solution
You may define the extension method in the control cs or vb file, below the section 1 region, and above all ISD-generated control classes. Below is an example of C# version,Using the extension method could not be simpler.
1 comment:
Great tip - thanks for sharing this.
Simon
Post a Comment