Don't want to use codebehind...

  • Thread starter Thread starter M
  • Start date Start date
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.
 
Perhaps the "inherits" or "src" on the @page directive could point to the
proper assembly?
 
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,
 
Back
Top