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
mark class
partial
set
autoeventwireup="true"
change
codebehind
propertycodebehind="default1.aspx.vb"
change
inherits
propertyinherits="your_namespace._default1"
Comments
Post a Comment