aspx variable replacement - runat=server

Discussion in 'ASP .Net' started by testemail@skunkbox.com, Jan 28, 2005.

  1. Guest

    Hello

    How do I perform a variable replacement in ASP.NET when I am using the
    runat=server clause to generate a table - it was simple in ASP

    With ASP :
    ----------
    <HTML>
    ....
    <BODY>
    ....
    <TABLE...>
    <TR>
    <TD colspan="<%=NumberOfCols%>">...<TD>
    ....
    <TR>
    ....
    <TABLE>
    ....
    </BODY>
    </HTML>

    With ASP.NET :
    --------------
    <HTML>
    ....
    <BODY>
    ....
    <asp:Table... runat=server>
    <asp:TableRow runat=server>
    <asp:TableCell ColumnSpan="<%=NumberOfCols%>"
    runat=server>...</asp:TableCell>
    ....
    </asp:TableRow>
    ....
    </asp:Table>
    ....
    </BODY>
    </HTML>

    Then the Code Behind contains
    ....
    Protected NumberOfCols As Integer = 6
    ....


    But executing the above <%=NumberOfCols%> is not a valid value for
    Int32.

    However if I print the variable by placing <%=NumberOfCols%> somewhere
    within the body of the html it prints the value of it ("6") correctly.
    Can anyone help ?

    Cheers
    Phil
     
    , Jan 28, 2005
    #1
    1. Advertising

  2. Phil,

    Try to remove the quotes:

    ColumnSpan=<%=NumberOfCols%>

    Eliyahu

    <> wrote in message
    news:...
    > Hello
    >
    > How do I perform a variable replacement in ASP.NET when I am using the
    > runat=server clause to generate a table - it was simple in ASP
    >
    > With ASP :
    > ----------
    > <HTML>
    > ...
    > <BODY>
    > ...
    > <TABLE...>
    > <TR>
    > <TD colspan="<%=NumberOfCols%>">...<TD>
    > ...
    > <TR>
    > ...
    > <TABLE>
    > ...
    > </BODY>
    > </HTML>
    >
    > With ASP.NET :
    > --------------
    > <HTML>
    > ...
    > <BODY>
    > ...
    > <asp:Table... runat=server>
    > <asp:TableRow runat=server>
    > <asp:TableCell ColumnSpan="<%=NumberOfCols%>"
    > runat=server>...</asp:TableCell>
    > ...
    > </asp:TableRow>
    > ...
    > </asp:Table>
    > ...
    > </BODY>
    > </HTML>
    >
    > Then the Code Behind contains
    > ...
    > Protected NumberOfCols As Integer = 6
    > ...
    >
    >
    > But executing the above <%=NumberOfCols%> is not a valid value for
    > Int32.
    >
    > However if I print the variable by placing <%=NumberOfCols%> somewhere
    > within the body of the html it prints the value of it ("6") correctly.
    > Can anyone help ?
    >
    > Cheers
    > Phil
    >
     
    Eliyahu Goldin, Jan 28, 2005
    #2
    1. Advertising

  3. Karl Seguin Guest

    Phil:
    In ASP.Net it's just as simple but far more flexible. The entire point of
    having a runat="server" is that it creates a rich and capable server-side
    object, in this case an HtmlTableCell. Instead of messing up your html code
    with <%= %> you can program against your objects to set their variables.

    In other words:

    <asp:TableCell id="cellContent" runat=server>...</asp:TableCell>

    and then you can do, in the Page_Load event:

    cellContent.ColumnSpan = NumberOfCols

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    <> wrote in message
    news:...
    > Hello
    >
    > How do I perform a variable replacement in ASP.NET when I am using the
    > runat=server clause to generate a table - it was simple in ASP
    >
    > With ASP :
    > ----------
    > <HTML>
    > ...
    > <BODY>
    > ...
    > <TABLE...>
    > <TR>
    > <TD colspan="<%=NumberOfCols%>">...<TD>
    > ...
    > <TR>
    > ...
    > <TABLE>
    > ...
    > </BODY>
    > </HTML>
    >
    > With ASP.NET :
    > --------------
    > <HTML>
    > ...
    > <BODY>
    > ...
    > <asp:Table... runat=server>
    > <asp:TableRow runat=server>
    > <asp:TableCell ColumnSpan="<%=NumberOfCols%>"
    > runat=server>...</asp:TableCell>
    > ...
    > </asp:TableRow>
    > ...
    > </asp:Table>
    > ...
    > </BODY>
    > </HTML>
    >
    > Then the Code Behind contains
    > ...
    > Protected NumberOfCols As Integer = 6
    > ...
    >
    >
    > But executing the above <%=NumberOfCols%> is not a valid value for
    > Int32.
    >
    > However if I print the variable by placing <%=NumberOfCols%> somewhere
    > within the body of the html it prints the value of it ("6") correctly.
    > Can anyone help ?
    >
    > Cheers
    > Phil
    >
     
    Karl Seguin, Jan 28, 2005
    #3
  4. Guest

    Thanks Karl, it's just that I've seen
    <%# DataBinder.Eval(<object>,"<fieldname>") %>
    in HTML and wondered if I should be somehow using this syntax or puting
    it in the code behind as you have suggested.

    Many thanks for your reply
    Phil



    Karl Seguin wrote:
    > Phil:
    > In ASP.Net it's just as simple but far more flexible. The entire

    point of
    > having a runat="server" is that it creates a rich and capable

    server-side
    > object, in this case an HtmlTableCell. Instead of messing up your

    html code
    > with <%= %> you can program against your objects to set their

    variables.
    >
    > In other words:
    >
    > <asp:TableCell id="cellContent" runat=server>...</asp:TableCell>
    >
    > and then you can do, in the Page_Load event:
    >
    > cellContent.ColumnSpan = NumberOfCols
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > <> wrote in message
    > news:...
    > > Hello
    > >
    > > How do I perform a variable replacement in ASP.NET when I am using

    the
    > > runat=server clause to generate a table - it was simple in ASP
    > >
    > > With ASP :
    > > ----------
    > > <HTML>
    > > ...
    > > <BODY>
    > > ...
    > > <TABLE...>
    > > <TR>
    > > <TD colspan="<%=NumberOfCols%>">...<TD>
    > > ...
    > > <TR>
    > > ...
    > > <TABLE>
    > > ...
    > > </BODY>
    > > </HTML>
    > >
    > > With ASP.NET :
    > > --------------
    > > <HTML>
    > > ...
    > > <BODY>
    > > ...
    > > <asp:Table... runat=server>
    > > <asp:TableRow runat=server>
    > > <asp:TableCell ColumnSpan="<%=NumberOfCols%>"
    > > runat=server>...</asp:TableCell>
    > > ...
    > > </asp:TableRow>
    > > ...
    > > </asp:Table>
    > > ...
    > > </BODY>
    > > </HTML>
    > >
    > > Then the Code Behind contains
    > > ...
    > > Protected NumberOfCols As Integer = 6
    > > ...
    > >
    > >
    > > But executing the above <%=NumberOfCols%> is not a valid value for
    > > Int32.
    > >
    > > However if I print the variable by placing <%=NumberOfCols%>

    somewhere
    > > within the body of the html it prints the value of it ("6")

    correctly.
    > > Can anyone help ?
    > >
    > > Cheers
    > > Phil
    > >
     
    , Jan 28, 2005
    #4
    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. Hazzard
    Replies:
    2
    Views:
    589
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
  2. Marina
    Replies:
    0
    Views:
    566
    Marina
    Jul 21, 2003
  3. Elliot M. Rodriguez
    Replies:
    0
    Views:
    631
    Elliot M. Rodriguez
    Jul 21, 2003
  4. z. f.
    Replies:
    1
    Views:
    489
    Mikhail Arkhipov \(MSFT\)
    Jun 25, 2004
  5. =?ISO-8859-1?Q?Roland_M=FCller?=

    Request a code behind property in aspx tag (runat server)

    =?ISO-8859-1?Q?Roland_M=FCller?=, Nov 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    564
    =?ISO-8859-1?Q?Roland_M=FCller?=
    Nov 11, 2005
Loading...

Share This Page