I am using dojo with .NET webforms for creating popup menu and I am getting below error when I try to load the page. "dojo/parser::parse() error TypeError: Cannot read property 'getAttribute' of undefined"
it would be very useful if someone can share a blog on how to use dojo with webforms. Below is my code for reference. please check and help me resolve this issue.
<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" CodeBehind="xyz.aspx.cs" Inherits="xyz" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link href="../Content/bootstrap.min.css" rel="stylesheet" />
<link href="../Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="../Content/claro.css" rel="stylesheet" />
<link href="../Scripts/dojo/resources/dojo.css" rel="stylesheet" />
<script type="text/javascript" src="../Scripts/jquery-1.12.4.js"></script>
<script type="text/javascript" src="../Scripts/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery-ui-1.12.1.js">
</script>
<script type="text/javascript" src="../Scripts/dojo/dojo.js" ></script>
</head>
<body class="claro" style="height:100px;width:100px;">
<div data-dojo-type="dijit/layout/BorderContainer" style="height:100%; width:100%">
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region: 'center'">
<div data-dojo-type="dijit/MenuBar">
<div data-dojo-type="dijit/PopupMenuBarItem">
<span>File</span>
<div data-dojo-type="dijit/DropDownMenu">
<div data-dojo-type="dijit/MenuItem">Open</div>
<div data-dojo-type="dijit/MenuItem">Save</div>
<div data-dojo-type="dijit/PopupMenuItem">
<span> Recent...</span>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
document.getElementById("pnlControlList").remove();
$("#navbar").remove();
require(["dojo/parser"], function (parser) {
parser.parse();
});
</script>
</body>
</html>
</asp:Content>
This piece of code causes problem:
<div data-dojo-type="dijit/PopupMenuItem">
<span> Recent...</span>
</div>
dijit/PopupMenuItem
needs to contain dropdown element as its child.
require(["dojo/parser",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dijit/MenuBar",
"dijit/PopupMenuBarItem", "dijit/DropDownMenu", "dijit/MenuItem", "dijit/PopupMenuItem"
], function (parser) {
parser.parse();
});
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.10.4/dijit/themes/claro/claro.css" />
<body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer" style="height:100px; width:100px">
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region: 'center'">
<div data-dojo-type="dijit/MenuBar">
<div data-dojo-type="dijit/PopupMenuBarItem">
<span>File</span>
<div data-dojo-type="dijit/DropDownMenu">
<div data-dojo-type="dijit/MenuItem">Open</div>
<div data-dojo-type="dijit/MenuItem">Save</div>
<div data-dojo-type="dijit/PopupMenuItem">
<span> Recent...</span>
<div data-dojo-type="dijit/DropDownMenu">
<div data-dojo-type="dijit/MenuItem">Some Item</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
Note: I've also added all dijit modules contained in html to required modules. I don't know whether it's mandatory in .NET but some environments throw error without it (ex. jsfiddle)