Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I create an inline function/method inside of a user control?

Tags:

c#

asp.net

I want to create an inline function/method inside of my user control, so that I can do this:

Inside my test.ascx:

<asp:Repeater ...>
  <itemTemplate>
     <p><%# MyInlineMethod(Eval("hello").ToString())%> </p>
  <itemTemplate>
</asp:Repeater>

is this possible?

like image 686
loyalflow Avatar asked Nov 20 '25 22:11

loyalflow


1 Answers

Yes it is possible but it has to be static method. And you will have to access it with fully qualified name or import the namespace.

<%@ Import Namespace="RootNamespace.SubNamespace1" %>

<asp:Repeater ...>
  <itemTemplate>
     <p><%# MyClass.MyInlineMethod(Eval("hello").ToString())%> </p>
  <itemTemplate>
</asp:Repeater>

Method definition

namespace RootNamespace.SubNamespace1
{
     public class MyClass
     {
         public static string MyInlineMethod(string input){
            return string.Format("{0}!!!",input);
         }
     }
}
like image 173
mipe34 Avatar answered Nov 22 '25 11:11

mipe34



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!