vb.net - ASP.NET Public Variable at Code Behind is not accesible in .aspx -


this simple example of happening here.

default.aspx

<%@ page language="vb" autoeventwireup="false" codebehind="default.aspx.vb" inherits="base._default1" %>      <!doctype html>      <html xmlns="http://www.w3.org/1999/xhtml">     <head runat="server">         <title></title>     </head>     <body>         <form id="form1" runat="server">         <div>         <% response.write(sname) %>         </div>         </form>     </body>     </html> 

and code behind default.aspx.vb

public class _default1     inherits system.web.ui.page      public sname string = "jimmy"      protected sub page_load(byval sender object, byval e system.eventargs) handles me.load      end sub  end class 

the error

bc30451 'sname' not declared. may inaccessible due protection level. base c:\users\jimmy\documents\visual studio 2015\projects\base\base\teste\default.aspx 12

where problem ?

the biggest issue class _default1 not marked partial class.

it should rather be

public partial class _default1       inherits system.web.ui.page 

one more point page directive has property autoeventwireup="false" , way have page events mapped right not work. set true rather autoeventwireup="true"

your @page directive total weird can seen below.

<%@ page autoeventwireup="false" codebehind="default.aspx.vb" inherits="base._default1" %> 

to summarize; below issues should take care off

  1. mark class partial

  2. set autoeventwireup="true"

  3. change codebehind property codebehind="default1.aspx.vb"

  4. change inherits property inherits="your_namespace._default1"


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -