Monday, November 17, 2014

Creating a "watermark" version label in your ASP.Net masterpage...

It's not uncommon to receive a screenshot from a user of a webpage with an issue. How do you know which version the printout came from?

I've used this simple piece of code to help document every page. Basically, create a simple readonly text/label control [ctlIssueDate] and assign the Text label dynamically.

protected override void OnLoad(EventArgs e)
      // Declarations
      System.Reflection.AssemblyName assemblyName;


      // Set page title to include version information.
      assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName();
      versionPanel.InnerHtml = "Version " + assemblyName.Version.Major.ToString() + "." + assemblyName.Version.Minor.ToString() +"." + assemblyName.Version.Revision.ToString();

      // Set default IssueDate
      ctlIssueDate.Text = DateTime.Now.ToShortDateString();
   catch (Exception ex)

No comments: