mercredi 24 juin 2015

Generate javascript if run [DEBUG] mode

Correctly I add javascript to the page? Is there a special System.Web.UI.Control for these purposes?

code in Site.Mastre.cs:

public partial class Site : System.Web.UI.MasterPage
{
  protected override void OnLoad(EventArgs e)
  {
    #if DEBUG
    Page.Header.Controls.Add
    (new LiteralControl("<script>" +
                        "alert(\"Hello! Run in [DEBUG] mode!\")");" +
                        "</script>"));
    #else
    Page.Header.Controls.Add
    (new LiteralControl("<script>" +
                        "alert(\"Hello! Run in [RELEASE] mode!\")");" +
                        "</script>"));
    #endif
    base.OnLoad(e);
  }
}

Aucun commentaire:

Enregistrer un commentaire