Am I in Edit or View mode
My first blog post as graduated will be a short one, but I promise more is coming. I recently got a question about how do you know if you are in Edit or Admin mode. Say you have a usercontrol that is used in both an Admin plugin and on a Template page. I now want to do something special if it is in the UI. I had a theory, discussed it with my team and got this solution:
Cast the page as a SystemPageBase and see if it is null. Since all pages in the UI inherit from SystemPageBase if we are in there it wont be null.
1: protected override void OnLoad(EventArgs e)
2: {
3: SystemPageBase ed = Page as SystemPageBase;
4:
5: if (ed != null)
6: {
7: Status.Text = "UI mode";
8: }else
9: Status.Text = "View mode";
10:
11:
12: DataBind();
13: base.OnLoad(e);
14: }
If you have a better solution for it please let me know.
/Jacob
21 August 2009