Inline output in pages

Discussion in 'ASP .Net' started by Mike Gleason jr Couturier, Jun 4, 2008.

  1. Hi,

    In an .aspx file, is there any clear/concise documentation about the
    difference between the following:


    <%$ [...]
    <%= [...]
    <%# [...]

    and where we can use them?

    How are those called?

    Thanks!

    Mike
     
    Mike Gleason jr Couturier, Jun 4, 2008
    #1
    1. Advertising

  2. The
    <%= is a substitute for Response.Write
    So <%= a%> is exactly the same as <%Response.Write(a)%> and executes only
    during Render even, and is used to write something to browser
    -----------------------------------------------
    <%# is called data binding. <%# Methods%> will be executed during so called
    "binding". It's used to assign some value to property

    Example:
    <asp:label text='<%# MyValue %>' runat="server"/>
    You can not write here <%= instead of <%# simply because it will not make
    sense. You want to assign to text property of the label the value of
    MyValue.

    PS. to kick of execution of data binding you need to call Page.DataBind();

    The most common use for <%# is in DataGrid and such. When you write
    <asp:TemplateColumn HeaderText="FAQ Information">
    <ItemTemplate>
    <b><%# DataBinder.Eval(Container.DataItem, "ColumnName") %></b>
    </ItemTemplate>
    </asp:TemplateColumn>this code is actually assignment to the ItemTemplate
    property. so you can not use <%= instead.PS: You do not need to call
    Page.DataBind() in this case but you do need to call MyGrid.DataBind() for
    assignment to actually happen. (Of course if you do not have Page scope
    biding
    elements) -----------------------------------------------------------------
    The
    <%$ is the synonymous for pulling value from the resource (or web.config ).
    My understanding that it happens during compile time. And not runtime.
    So you can not write someting like
    "<%$ ConnectionStrings:GetMyConnection()%>"
    Becuase GetMyConnection is evaluated during parse time and your code is not
    running at that time.

    George


    "Mike Gleason jr Couturier" <> wrote in message
    news:...
    > Hi,
    >
    > In an .aspx file, is there any clear/concise documentation about the
    > difference between the following:
    >
    >
    > <%$ [...]
    > <%= [...]
    > <%# [...]
    >
    > and where we can use them?
    >
    > How are those called?
    >
    > Thanks!
    >
    > Mike
    >
     
    George Ter-Saakov, Jun 4, 2008
    #2
    1. Advertising

  3. "George Ter-Saakov" <> a écrit dans le message de news:
    %23T%...
    > The
    > <%= is a substitute for Response.Write
    > So <%= a%> is exactly the same as <%Response.Write(a)%> and executes only
    > during Render even, and is used to write something to browser
    > -----------------------------------------------
    > <%# is called data binding. <%# Methods%> will be executed during so
    > called "binding". It's used to assign some value to property
    >
    > Example:
    > [...]


    Thank you very much, it is now 100% clear in my head, thanks again!

    Mike
     
    Mike Gleason jr Couturier, Jun 4, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Abhi
    Replies:
    2
    Views:
    750
    E. Robert Tisdale
    Jul 3, 2003
  2. Alvin
    Replies:
    7
    Views:
    487
    E. Robert Tisdale
    May 6, 2005
  3. Replies:
    3
    Views:
    471
  4. Daniel Vallstrom
    Replies:
    2
    Views:
    1,940
    Kevin Bracey
    Nov 21, 2003
  5. Nish
    Replies:
    4
    Views:
    506
    Thomas Stegen
    Oct 8, 2004
Loading...

Share This Page