jumpstart0321
asked on
Adding javascript programatically via ASP.net
Ok, I have some javascript that I can run by inputting it into the <head> section of my code. This Javascript automatically fires on page load. The code takes the syntax:
<head>
<script type="text/javascript">
Javascript code here
</script>
</head>
This works great, however I need to add the code programatically because the code has dynamic variables that need to be added. So, I took on this method to add the Javascript via code:
Dim header As LiteralControl = New LiteralControl
header.Text = "JAVASCRIPT CODE"
Me.Page.Header.Controls.Ad d(header)
This code visually shows up fine if I check the source code, however it is not firing. I have checked and recked the source code and it generates identical source as the original. Anybody know what the problem is? If anyone wishes to reference my exact code, I will list it below:
<head>
<script type="text/javascript">
Javascript code here
</script>
</head>
This works great, however I need to add the code programatically because the code has dynamic variables that need to be added. So, I took on this method to add the Javascript via code:
Dim header As LiteralControl = New LiteralControl
header.Text = "JAVASCRIPT CODE"
Me.Page.Header.Controls.Ad
This code visually shows up fine if I check the source code, however it is not firing. I have checked and recked the source code and it generates identical source as the original. Anybody know what the problem is? If anyone wishes to reference my exact code, I will list it below:
<script type="text/javascript">
var AjaxEnginePage;
var ClientInfoPage;
var XMLHTTP;
AjaxEnginePage = "ProcessBadLink.aspx";
ClientInfoPage="BadLink.aspx";
var MerchantID = 21432;
var requestUrl =AjaxEnginePage + "?MerchantID="+ MerchantID;
CreateXMLHTTP();
if(XMLHTTP)
{
XMLHTTP.open("POST", requestUrl, true);
XMLHTTP.send(null);
}
function CreateXMLHTTP()
{
try
{
XMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(oc)
{
XMLHTTP = null;
}
}
if(!XMLHTTP && typeof XMLHttpRequest != "undefined")
{
XMLHTTP = new XMLHttpRequest();
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.