Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net calling a method from front end

Tags:

c#

asp.net

i have a method in my back end that i would like to call from my front end, but can't seem to get it working. here is my code:

<% foreach(string item in Plants){ %>

    <li>
        <span class="folder">
            <asp:label ID="lblPlantName" runat="server" Text='<% GetPlantName(item) %>'></asp:label>
        </span>
    </li>

<%} %>

the getplantName method should return a string and fill the text in. But this is not getting called for some reason.

Anyone have any ideas or suggestions?

like image 995
Funky Avatar asked Nov 30 '22 08:11

Funky


2 Answers

Please use <%= GetPlantName(item) %> instead of <% GetPlantName(item) %> and method should be Public or Protected.

like image 59
Shailesh Avatar answered Dec 15 '22 01:12

Shailesh


To return a string you need Response.Write which is written in shorthand as <%=%> so:

<%= GetPlantName(item) %>
like image 23
Chris Haas Avatar answered Dec 15 '22 01:12

Chris Haas