troubleshooting Question

Adding javascript programatically via ASP.net

Avatar of jumpstart0321
jumpstart0321 asked on
JavaScriptASP.NET
2 Comments2 Solutions314 ViewsLast Modified:
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.Add(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:
<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
Rajkumar Gs
Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros