简体   繁体   English

在<%=%>中找不到变量

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM