0

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>();
        }
    }
}
Buraktncblk
  • 31
  • 2
  • 9
  • 1
    Firstly correct syntax is `<%= %>` or if u binding data in repeater or something else `<%# %>` and can you check variables are public ? – Erdem Ozdemir Nov 18 '19 at 14:54
  • 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 Nov 18 '19 at 15:10
  • 3
    Can you replace the screenshots with the actual text content of your code? https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question –  Nov 18 '19 at 16:19
  • @ErdemOzdemir variables has public or protected modifiers. – Buraktncblk Nov 19 '19 at 06:32
  • @Amy I added code and screenshot. – Buraktncblk Nov 19 '19 at 06:37
  • If you want to repeat dictionary you must bind repeater with dictionary. If you would use mvc you could bind like that with model but in webforms this syntax a little bit weird in my opinion :) You can refer dictionary binding [here](https://stackoverflow.com/questions/2274875/bind-dictionary-to-repeater) – Erdem Ozdemir Nov 19 '19 at 07:36
  • @ErdemOzdemir its sample, type does not matter.(string, datetime, tuple, class and other) public/protected variables and methods not accessible aspx side. – Buraktncblk Nov 20 '19 at 06:32

1 Answers1

0

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"
Buraktncblk
  • 31
  • 2
  • 9