无法从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 %>%">
            &nbsp;</td>
        <td colspan="0" rowspan="0">
            &nbsp;</td>
    </tr>

我已经使用了<%= progressbar %><%# progressbar %>,但无法访问这个变量。
你能告诉我如何从c#代码到asp.net页面访问这个变量吗

无法从aspx页面后面的代码访问变量

  1. 确保你要访问的变量不是私有的

  2. 你应该可以像这样访问它<%= progressbar %>

write 类中的

public int progressbar = 0;

c#中的所有变量都是局部变量,它们只在声明它们的函数内部可见。让你的东西成为一个字段或属性,并确保它是protectedpublic