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>