0
votes

I develop aspx web project in VS2017. I can't access code behind methods or variables from aspx side inline expression.If I try this block <% this.data1 %> to access variables and visual studio throws

" panel_islemler_test_aspx does not contain a definition for data1 and no accessible extension method data1 accepting a first argument of type panel_islemler_test_aspx could be found (are you missing a using directive or an assembly reference?)".

(Same problem on Visual Studio 2019)

enter image description here

test.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" 
    Inherits="ProjeYonetimWEB.Panel.islemler.test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <!-- Not Working -->
            <% foreach (var kvp in this.data1)
                {%>
                    <span><%= kvp %></span>
            <%} %>
            <span><%= this.method("abc") %></span>
            <p><%= this.data2 %></p>
            <p><%= this.data3  %></p>
        </div>
    </form>
</body>
</html>

test.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjeYonetimWEB.Panel.islemler
{
    public partial class test : System.Web.UI.Page
    {
        public Dictionary<int, string> data1;
        public Dictionary<int,string> data2 { get; set; }

        protected Dictionary<string,string> data3;

        public string method(string s)
        {
            return s;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            data1 = new Dictionary<int, string>();
            data2 = new Dictionary<int, string>();
            data3 = new Dictionary<string, string>();
        }
    }
}
1
Firstly correct syntax is <%= %> or if u binding data in repeater or something else <%# %> and can you check variables are public ? - Erdem Ozdemir
I just noticed that the screen you displayed is test.aspx while the error was on panel_islemler_test.aspx. Can you provide the markup on the latter web form? - Angelo
Can you replace the screenshots with the actual text content of your code? meta.stackoverflow.com/questions/285551/… - user47589
@ErdemOzdemir variables has public or protected modifiers. - Buraktncblk
@Amy I added code and screenshot. - Buraktncblk

1 Answers

0
votes

Problem solved. When I change build platform target x64 to any cpu it works properly.

Steps;

Project > RightClick > Properties
Build tab > Platform Target set to "Any CPU"