Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Code with Master/Content Pages

Status
Not open for further replies.

djs45uk

Technical User
Nov 7, 2004
103
GB
Master Pages look great but what happens when you're using master/content pages and in your content pages you want to use some code (functions for example)?

The code needs to go in the <script></script> tags which appear in the Head of the Master Page.

Surely you don't have to put all your code and functions into the master page, even if you only want to use it on just one content page? That seems like a massive overhead when you consider how many functions you might have throughout your site.

Am I missing something crucial?

Thanks

DS
 
nope.

you can insert <script> tags anywhere in the content page and they will run just fine. I do it all the time.

the only time you should put script in the master page is if that script is executing for stuff in the master page, not in the content page.

<asp:content>
<script language=javascript>

</script>

</asp:content>
 
You can just use ClientScript.RegisterClientScriptBlock from your content pages to add whatever javascript functions you need.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
I'm sorry, I don't mean JavaScript.

I mean if you wanted to use something like this

Function RandNum(Limit As Integer) As Integer
Dim Num As Integer
Randomize
Num=Int(Rnd * Limit)+1
Return(Num)
End Function

And you wanted to call this function in your Content page. Functions like this have to go in <script runat="server"></script> tags in the Head don't they?

If that is the case, you'd have to put all your functions for the entire site into the Master Page.
 
No, they dont have to go into the <head> tag. You can put them anywhere. The code behind file is the easiest place, tho.
 
And you wanted to call this function in your Content page. Functions like this have to go in <script runat="server"></script> tags in the Head don't they?
No they don't and in most cases shouldn't go in script tags at all. Instead, use the code-behind model of whichever page you are using (whether that is a master, content or standard page is irrelevant).


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Ah ok I see! I haven't been using the code-behind file, I've been putting my code in the page itself but I will give that a go!

Many thanks to both of you for the advice.

DS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top