locked
The name 'loadXMLDoc' does not exist in the current context RRS feed

  • Question

  • User618007423 posted

    Could someone tell me why I am getting the above error? Thank you. The first code snippet is default.aspx.cs and the second is an external LoadXMLDoc.js.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data;
    using System.Xml;
    
    
    namespace NBSWorkOrder
    {
        public partial class _default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                   var xmlDoc = loadXMLDoc("books.xml");
    
                }
            }
    
            protected void Button1_Click(object sender, EventArgs e)
            {
            }
        }
    }
    function loadXMLDoc(filename) {
        if (window.XMLHttpRequest) {
            xhttp = new XMLHttpRequest();
        }
        else // code for IE5 and IE6
        {
            xhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xhttp.open("GET", filename, false);
        xhttp.send();
        return xhttp.responseXML;
    }




    Thursday, January 8, 2015 10:10 AM

Answers

  • User-821857111 posted

    You can't call client-side JavaScript functions from your server-side Page_Load method. If you want to manipulate XML in your Page_Load event, you need to use C#. You can use the XDocument type for that:

    var xmlDoc = XDocument.Load(path_to_your_xml_file);



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 8, 2015 12:06 PM