0

I was wondering what the best way to use an inline expression on a say a label control. Example. Using a Data bind inline expression addnumbers.cs `

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication2
{
    public class addnumbers
    {
        public string names { get; set; }

        public int totals() {
            return 2+2;
        }

    }

}

`

ASPX Markup

    <asp:Label ID="Label1" runat="server" Text="<%#addnumbers.totals() %>"></asp:Label>

addnumbers class is not in the codebehind of the ASPX page markup is a class i want to pass the method value to.

Thanks

Will this do

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApplication2.test" %>
<%@ Import Namespace ="WebApplication2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<script runat = "server">
          protected int GetTotal()
          {
              addnumbers ctr = new addnumbers();
              return ctr.totals();

          }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 87px">

 <p> The Total is  <%=GetTotal()%></p>


    </div>


    </form>
</body>
</html>
MautaI
  • 3
  • 3
  • [Make it static](http://stackoverflow.com/questions/15556086/accessing-static-class-method-from-aspx-page)? Bad design though, you may want to call `new addnumbers().totals()` and store the result in a property of your page, binding to that. – CodeCaster Feb 08 '15 at 10:57
  • This is just a pseudo by the way, but is this what you mean – MautaI Feb 08 '15 at 11:33
  • – MautaI Feb 08 '15 at 11:39

0 Answers0