Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I generally advise creating a BasePage class of some sort that encapsulates the behavior you want through all of your pages, these objects are assumed to always have the same master page, if you need other setups then you can create other objects as necessary.</p> <p>From there you can create some properties or methods to allow the BasePage objects to access the master page or its associated properties in a very easy to code way such as this.Title = "MyTitle"</p> <p>You can get fancier and create some virtual methods on your BasePage class that you can then override on the physical pages as necessary, to set titles, etc, as needed, without ever grabbing the Master page object directly (which yes, is annoying and ugly). This might look something like this.Title = GetTitle(); (GetTitle is a virtual method on the BasePage that is overridden in the child pages as needed for those pages you want to set a title for).</p> <p>This makes strong use of inheritance and lets you add functionality to all of your pages very easily, it may be overkill for what your doing but I've never found a situation that was too simplistic for this architecture, it just works really well. I personally find this design far better than constantly using FindControl(), which tends to be error-prone when control ID's change, etc.</p> <ol> <li><p>FindControl() is bad because if the control ID's change, then you might forget to update them in the FindControl reference, and now it'll break the next time its executed, I stay well away from static stuff like this if at all possible for this very reason, it's a cheap, quick but error-prone solution.</p></li> <li><p>Accessing the Master page directly isn't inherently bad, I just can't stand stuff like:</p> <p>myMasterPage myMaster = (myMasterPage)this.Master</p></li> </ol> <p>Gets old, is uglier than it needs to be, wrap it in an accessor property at the very least ;)</p> <p>I like the following better:</p> <pre><code>Title = "My Title"; // Property </code></pre> <p>or</p> <pre><code>Title = GetTitle(); // Virtual method </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload