2 Replies - 1732 Views - Last Post: 20 June 2012 - 05:55 AM Rate Topic: -----

#1 thursdayniac  Icon User is offline

  • D.I.C Regular

Reputation: 6
  • View blog
  • Posts: 255
  • Joined: 26-April 09

Setting src of script tag in code-behind (am i doing it right?)

Posted 19 June 2012 - 12:39 PM

Hi All,

So in my aspx mark up, I have a script tag. in this tag, I would like to set the src property in the code-behind (will be getting this value from web.config)

So here is what I did:
in the aspx page, I have my script tag:
<script type="text/javascript" src="<%=someUrl%>"></script>



And in the aspx.cs, I have:
protected string someUrl { get; set; }


as a class level var, and then I have:
protected override void OnPreRender(EventArgs e)
{
      someUrl = "https://myurl.com/file?id=SCRIPTID";
      base.OnPreRender(e);
}



Is this a good way to go about it? It seems to be working. Thanks!

Is This A Good Question/Topic? 1
  • +

Replies To: Setting src of script tag in code-behind (am i doing it right?)

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Setting src of script tag in code-behind (am i doing it right?)

Posted 20 June 2012 - 05:29 AM

If it works, I don't see why it would be wrong. Looks fine to me.
Was This Post Helpful? 0
  • +
  • -

#3 anonymouscodder  Icon User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: Setting src of script tag in code-behind (am i doing it right?)

Posted 20 June 2012 - 05:55 AM

It doesn't seem wrong for me either.

An alternative would be using the ScriptManager Class, but beware the postback.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1