views:

310

answers:

3

Heres the problem,

In Masterpage, the google analytics code were pasted before the end of body tag.

In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript and put it before the end of body tag, because this script uses the google analytics variables.

How can i achieve this?

A: 

You could delay your script execution until after the page loads, then it won't matter where your script resides.

Quintin Robinson
how can i do that?
Fleents
+1  A: 

Take a look at RegisterStartupScript

The script block will be placed right above the </form> tag at the end of the page.

Alison
A: 

An inelegant but simple approach, if you're able to avoid using ClientScript, would be to just stick a literal in the page where you want your script to be rendered and put the script in there from your codebehind (i.e. myLiteral.Text = "client script";).

kristian
I was gonna post this, but I realized it would have to be in the master page, and therefore not accessible from his detail page via the normal means.
Joel Coehoorn
Good point Joel, I missed the bit about the master page. Sticking with the "inelegant-but-simple" theme, you could still get the literal with a good old Page.Master.FindControl("myLiteral") though.
kristian