结果报错,运行时错误: 此上下文中不支持代码块。 D:\web\w\test.aspx
在LABEL的时候运行可以,但是在textbox中就不可以了?是不是位置不对?aspx.cs文件中public partial class sql200 : System.Web.UI.Page
{ public string tit="测试";
protected void Page_Load(object sender, EventArgs e)
{
}
}aspx文件中 ,这样不可以。。
<td>
<asp:TextBox ID="TextBox1" runat="server" ><% =tit %></asp:TextBox>
</td>下面这个可以,
<td>
<asp:label ID="label1" runat="server" ><% =tit %></asp:label>
</td>
在LABEL的时候运行可以,但是在textbox中就不可以了?是不是位置不对?aspx.cs文件中public partial class sql200 : System.Web.UI.Page
{ public string tit="测试";
protected void Page_Load(object sender, EventArgs e)
{
}
}aspx文件中 ,这样不可以。。
<td>
<asp:TextBox ID="TextBox1" runat="server" ><% =tit %></asp:TextBox>
</td>下面这个可以,
<td>
<asp:label ID="label1" runat="server" ><% =tit %></asp:label>
</td>
public partial class sql200 : System.Web.UI.Page
{ public string tit="测试";
protected void Page_Load(object sender, EventArgs e)
{ this.TextBox1.Text = tit;
}
}
<td>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
</td>
或者
Text="<%# tit %>"
并在Page_Load里调用this.DataBind();
如果还是不行就在后台代码里赋值吧
TextBox1.Text = tit;
{ public string tit="测试";
protected void Page_Load(object sender, EventArgs e)
{ this.TextBox1.Text = tit;
}
}这样是可以的,但是在aspx文件中,
<td>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
</td>Text="<%= tit %>" 不行
Text=‘<%= tit %>’ 不行
Text=<%= tit %> 不行
<asp:TextBox ID="TextBox1" runat="server" ><%= tit %></asp:TextBox> 不行
提示:此上下文中不支持代码块。
看了textbox1不能在aspx文件调用变量。