0

I have added an attribute isAdmin to an HTML tag as below:

Partial Class Controls_View_ViewOrder
Inherits System.Web.UI.UserControl
Protected Overrides Sub OnInit(e As EventArgs)

    Dim isAdmin = Page.RouteData.Values("UserAdmn")
    rowMenu.Attributes.Add("isadmin", isAdmin)

End Sub
End Class

Trying to get the value of isAdmin by JavaScript as below:

<div class="rowMenu" id="rowMenu" runat="server"> </div>
.
.
.
let isAdmin = document.getElementById("rowMenu").getAttribute("isadmin");

but I got the below error: enter image description here

When I try to get the value of isAdmin I got error

0

1 Answer 1

3

The issue is with this line:

<div class="rowMenu" id="rowMenu" runat="server"> </div>

Please write the code in this way:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Scrap._Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
             <div class="rowMenu" id="rowMenu" isadmin="<%= Page.RouteData.Values("UserAdmn") %>" > </div>
             <script type="text/javascript">
                let isAdmin = document.getElementById("rowMenu").getAttribute("isadmin");
                alert(isAdmin);
            </script>
        </div>
    </form>
</body>
</html>
Sign up to request clarification or add additional context in comments.

6 Comments

it didn't work! I added the ClinetIdMode to the div: <div class="rowMenu" id="rowMenu" ClientIDMode="Static" > AND tried to get the value like this: document.getElementById("<%= rowMenu.ClientId %>").getAttribute("isadmin"); AND removed runat="server"
tried them all separately, could you update your answer? for the options 1 or 2?
still not working.
I need to add the isadmin attr from the code behind! using this rowMenu.Attributes.Add("isadmin", isAdmin) when i remove the runat="server" I got compilation error!
your solution doesn't work
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.