populate google analytics code from textfile in MasterPage (Page_Init) RRS feed

  • Question

  • User944339287 posted

    Dear all,

    This is my solution to populate google analytics code from textfile in MasterPage (Page_Init)

    Is it a good way?

            If File.Exists(Server.MapPath("App_Data/google-analytics-code.txt")) Then
                Page.Header.Controls.Add(New LiteralControl(File.ReadAllText(Server.MapPath("App_Data/google-analytics-code.txt"))))
            End If

    Tuesday, November 3, 2020 2:50 AM

All replies

  • User-939850651 posted

    Hi kengkit,


    Raised after all controls have been initialized and any skin settings have been applied. The Init event of individual controls occurs before the Init event of the page.

    You could also use this event to read or initialize control properties.

    According to your code, it just loads some text content in the master page. But if only for this purpose, I think you could also try to implement it in Page_Load.

    If I misunderstood something, please let me know.

    Best regards,

    Xudong Peng

    Wednesday, November 4, 2020 7:52 AM