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)
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>();
}
}
}