Don't want to use codebehind...

M

M

Hello. I need an example of how to call an assembly function/method from a
webform page. I don't want to use a codebehind (nor embedded c# code), like
so:

<asp:DataGrid runat="server" id="Datagrid2" DataSource=<%#
getMyList(Convert.ToString(DataBinder.Eval(Container.DataItem, "Location")),
Convert.ToString(DataBinder.Eval(Container.DataItem, "Type")))%>
AutoGenerateColumns="false">


In the above, getMyList is in a codebehind. Is there a way, and if there is,
what is the syntax, to call this method from the assembly c# code, rather
than the code behind?


Thanks in advance.
 
M

M

Perhaps the "inherits" or "src" on the @page directive could point to the
proper assembly?
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi M,

You can include a namespace by using this sintax:

<% @Import Namespace="CTPCore" %>

Other thing, an assembly does not have function/methods , an assembly has
classes that in turn have methods , if you want to call a method that is a
member of a class then you must create an instance of this class ( unless
that the method be static ) and then you can call the method.

As in your example you have two ways to implement getMyList:
1- declare it in the page itself as you used to do in the old asp days :)
2- declare it in a class on the assembly, declare it as protected or public
, then declare that this page inherit from that other class using a
construction like:
note : I have never tested this before, but it should work
<%@ Page language="c#" AutoEventWireup="false"
Inherits="ASSEMBLY_NAME.CLASS_NAME" %>

Any of these two methods should work fine, now the big question, why you
don't want to use the codebehind mode?

Hope this help,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top