[英]can't find variable in <%=%>
I added a new web form in asp.net application which named Home. 我在asp.net应用程序中添加了一个名为Home的新Web表单。 In
Home.aspx.cs
I used these following codes : 在
Home.aspx.cs
我使用了以下代码:
public partial class Home : System.Web.UI.Page
{
protected string str = "Hello and welcome to c#";
protected void Page_Load(object sender, EventArgs e)
{
}
}
Then I go to Home.aspx
but unfortunately It won't find str
variable. 然后我去了
Home.aspx
但是不幸的是它找不到str
变量。
These are the codes in Home.aspx
: 这些是
Home.aspx
中的代码:
<body>
<form id="form1" runat="server">
<div>
<%=str %>
</div>
</form>
It seems it's a problem with asp.net error. 看来这是asp.net错误的问题。 Because it shows me error but when I start without debugging it show me the string and won't show any error after that.
因为它向我显示错误,但是当我在不调试的情况下启动时,会向我显示字符串,并且此后不会显示任何错误。
By the way there's no problem with protected. 顺便说一句,保护没有问题。
your str
variable should be public
not protected
, use like: 您的
str
变量应为public
而不是protected
,使用方式如下:
public partial class Home : System.Web.UI.Page
{
public string str = "Hello and welcome to c#";
protected void Page_Load(object sender, EventArgs e)
{
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.