0

Below is the static class within a solution, namespace WebApplication1

{
    public static class LabelValues
    {
        public static string GetLabelValue(string str)
        {
            Return "Hello" + str; //There's a complicated logic for this
        }
    }
}

Now I want set Label text using below code. but its not working

<asp:Label ID="_label1" runat="server" Text="<%# LabelValues.GetLabelValue("_label1") %>" >

I want to call static class from Text attribute of label control to set values for labels.

UDS
  • 13
  • 1
  • 8
  • Please include the error message you get. – Daz Aug 14 '18 at 10:51
  • The name "LabelValues" does not exist in current context. – UDS Aug 14 '18 at 10:57
  • Have you added the namespace that LabelValues exists in to the ASPX page? – Daz Aug 14 '18 at 10:58
  • Write out the complete namespace: `WebApplication1.LabelValues.GetLabelValue("_label1")` – VDWWD Aug 14 '18 at 11:00
  • I think you have to take a look here : [https://stackoverflow.com/questions/8967763/how-to-get-controls-in-static-web-method](https://stackoverflow.com/questions/8967763/how-to-get-controls-in-static-web-method) [https://stackoverflow.com/questions/2133194/access-asp-net-control-from-static-webmethod-js-ajax-call](https://stackoverflow.com/questions/2133194/access-asp-net-control-from-static-webmethod-js-ajax-call) – Ahmed Ramadan Aug 14 '18 at 12:20

1 Answers1

0

As VDWWD has mentioned you can write out the complete namespace. Also for data binding syntax I believe you need to wrap it in single quotes.

<asp:Label ID="_label1" runat="server" Text='<%# WebApplication1.LabelValues.GetLabelValue("_label1") %>' >

As seen here https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/bda9bbfx(v=vs.100)