例如:<asp:Label id="Label1" runat="server"><%=temp%></asp:Label>
这个句子,一运行就出错?为什么?

解决方案 »

  1.   

    <asp:Label id="Label1" runat="server" Text='<%=temp%>'></asp:Label>
      

  2.   

    不报错,但还是出不来阿?我在vb程序里这样定义:
    Public Class customItems
       Inherits System.Web.UI.Page
        #Region " Web Form Designer Generated Code "(略)
        Public temp As String = "hello,friends!"
     
       Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)     
               Handles MyBase.Load
                    ...........
       End Sub
      

  3.   

    用<%# temp %>和databind()方法是可以的,但上边所说的情况为什么不可以呢?
    那位好心的大侠能为我解惑啊?
      

  4.   

    用<%=temp%>在这个页面的前页要声明temp
      

  5.   

    例如<script runat="server">
         long temp=10;</script>
      

  6.   

    你在页面加载时作Page.DataBind()方法了吗?
    要不然是不会邦定任何值得!asp.net我是这样作的!但在vb里不知道还能用吗?
    在.cs里面建立一个属性
    public string Temp
    {
    get
    {
    return temp;  
    }
    set
    {
    temp=value;
    }
    }然后再里面这样
    <asp:Label id="Label1" runat="server" Text='<%# Temp %>'></asp:Label>
    记得一定要在Page_load()事件中调用Page.DataBind()方法
      

  7.   

    晕!可能使我表达的不清楚,我是vb.net写的,并且已经给temp传值了呀!
    Public Class customItems
       Inherits System.Web.UI.Page
       Public temp As String = "hello,friends!"
     
       Private Sub Page_Load.......
      

  8.   

    搞不懂楼主为什么非得要加个服务器控件来浪费资源
    tmp = "hello,friends!"
    <%=tmp%>

    <asp:Label id="Label1" runat="server">hello,friends!</asp:Label>  的结果不就是一样的嘛
      

  9.   

    要么在后台绑定Label1.Text = temp;要么直接<%=temp%>
      

  10.   

    这样写吧:
    <asp:Label id="Label1" runat="server"><%Response.Write(temp)%></asp:Label>我用C#,要加分号<%Response.Write(temp);%>,vb可能不用加。
      

  11.   

    <asp:Label id="Label1" runat="server"><%=temp%></asp:Label>
    不能这么用!!!
    你这个跟
    <%
    function sss
    alert('sss');
    end function
    %>
    <input type=button onclick="sss">
    没什么区别!就是说,.net的代码不是面条式执行的,不能把面条式代码放到服务器端控件,如果要放要用绑定<%# %>
      

  12.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    Trace.Warn("---------");
    } <%
    temp="tttttttttttttt";
    Trace.Warn("=================="); %>跟踪信息 
    类别 消息 From First(s) From Last(s) 
    aspx.page Begin Init   
    aspx.page End Init 0.000084 0.000084 
     --------- 0.000150 0.000065 
    aspx.page Begin PreRender 0.000196 0.000046 
    aspx.page End PreRender 0.000239 0.000043 
    aspx.page Begin SaveViewState 0.000555 0.000316 
    aspx.page End SaveViewState 0.001163 0.000608 
    aspx.page Begin Render 0.001233 0.000069 
     ================== 0.002411 0.001178 
    aspx.page End Render 0.003548 0.001137 
    能否得出些什么呢?个人认为是在把页面发送给浏览器前解释<%%>里的代码,而后台代码是在晕,我也解释不清,但总觉得跟这个有关系
      

  13.   

    http://www.ccw.com.cn/htm/center/prog/02_3_12_2.asp
      

  14.   

    <asp:Label id="Label1" runat="server" Text='<% = temp %>'></asp:Label>
    是对的.可能是你的其它的不对吧!
      

  15.   

    <asp:Label id="Label1" runat="server" Text='<% = temp %>'></asp:Label>
    改成
    <asp:Label id="Label1" runat="server" Text='<%=temp()%>'></asp:Label>
    后台定义函数如下
    public string temp()
    {
        string aa=Label1.Text;//等等代码自己看情况写
        return aa;
    }
    将这个改写成vb也很简单的吧!!!
      

  16.   

    在C#里面,<%=temp%>是完全可以用的。
    个人认为asp.net兼容asp的方法
    .aspx
    <%=temp%>
    .cs
    protected string temp;