2

I added a new web form in asp.net application which named Home. In Home.aspx.cs I used these following codes :

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.

These are the codes in Home.aspx :

    <body>
    <form id="form1" runat="server">
    <div>
    <%=str %>
    </div>
    </form>
4

2 回答 2

0

看来这是asp.net错误的问题。因为它向我显示错误,但是当我在没有调试的情况下开始时,它会向我显示字符串,之后不会显示任何错误。

顺便说一句,受保护的没有问题。

于 2013-01-28T11:21:54.720 回答
-2

你的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)
    {

    }
}
于 2013-01-28T11:07:11.977 回答