无法从aspx页面后面的代码访问变量
本文关键字:代码 访问 变量 aspx | 更新日期: 2023-09-27 17:50:19
我在后面的代码中声明了一个变量变量名为progressbar,类型为int
访问同一asp.net页面中的此变量,我使用以下代码
<table align="center" border="1" cellpadding="0" cellspacing="0" frame="border"
style="border-color: #FF0000" width="100%">
<tr>
<td bgcolor="#FF0066" colspan="0" rowspan="0" width="<%= progressbar %>%">
</td>
<td colspan="0" rowspan="0">
</td>
</tr>
我已经使用了<%= progressbar %>
和<%# progressbar %>
,但无法访问这个变量。
你能告诉我如何从c#代码到asp.net页面访问这个变量吗
-
确保你要访问的变量不是私有的
-
你应该可以像这样访问它
<%= progressbar %>
public int progressbar = 0;
c#中的所有变量都是局部变量,它们只在声明它们的函数内部可见。让你的东西成为一个字段或属性,并确保它是protected
或public
。