one way to do it is to use a Custom Control page. Add an Web User Control (.ascx) page in your website and put your script code in it
<script type="text/javascript">
function GetappId() {
var k = "<%=System.ConfigurationManager.AppSettings["facebookAppID"].ToString(); %>"
alert(k);
return k
}
</script>
now register your control to the page where you want the GetappId function like this
<%@ Register TagPrefix="Scrpt" TagName="GlobalScrpt" Src="~/WebUserControl.ascx" %>
** this tag goes after the <%@ Page %> tag in aspx page
then in the head section of your aspx page call the control like this
<head runat="server">
<title></title>
<Scrpt:GlobalScrpt ID="Scrpt1" runat="server" />
</head>
** ensure you have runat="server" in you header tag
now you can call GetappId() and get the desired result anywhere in the aspx page.
update - another solution
another way is to create an aspx (let's say the page is Default1.aspx) page without separate code behind page and place your code there
<%@ Page Language="C#" %>
function GetappId()
{
var k = "<%=System.ConfigurationManager.AppSettings["facebookAppID"].ToString(); %>";
alert(k);
}
then in the page where you want to call GetappId add the first aspx page as a javascript page.
<head runat="server">
<title></title>
<script type="text/javascript" src="Default1.aspx"></script>
</head>
now call your function anywhere in the page.