How to reference module function from inline script in ASPX?

  • Thread starter kevin buchanan via .NET 247
  • Start date
K

kevin buchanan via .NET 247

I have a ASP.NET web app with a common module. How can I access the Public functions in the common module from the 'in-line' scripts in the ASPX page?

...from the ASPX page...

<asp:Label runat="server"
BackColor='<%# System.Drawing.ColorTranslator.FromHTML(Module1.WarnLOS(Module1.LOSMinutes(DataBinder.Eval(Container.DataItem,"vAdmDtTm"))))%>'
Text='<%# DataBinder.Eval(Container, "DataItem.rmDesc")%>'
ID="Label2">
</asp:Label>


The Public functions in the common module (WarnLOS and LOSMinutes) do some conversions, but I reuse these function in a lot of the pages - so I wanted to put them in one place - the common module.

THE PROBLEM: I get this error:
Compiler Error Message: BC30451: Name 'Module1' is not declared.
When I try to access the functions from the common module. How do I declare Module1 from the in-line scripts?
 
P

Paul Glavich [MVP ASP.NET]

You can use this directive at the top of your ASPX page
<%@ Import namespace="CommonModileNamespace" %>

to access the Module1 without any namespace qualifier at the start of the
class definition. Otherwise, you can still access the common functions
(provided the DLL they reside in is in the /bin directory) but you must
fully quialify the class declaration such as:

RootNameSpace.YourProjectNamespace.Module1 obj = new
RootNameSpace.YourProjectNamespace.Module1();
obj.WarnLOS();

when you use the Import directive you can do

Module1 obj = new Module1();
obj.WarnLOS();


--

- Paul Glavich
ASP.NET MVP
ASPInsider (www.aspinsiders.com)


kevin buchanan via .NET 247 said:
I have a ASP.NET web app with a common module. How can I access the
Public functions in the common module from the 'in-line' scripts in the ASPX
page?
..from the ASPX page...

<asp:Label runat="server"
BackColor='<%# System.Drawing.ColorTranslator.FromHTML(Module1.WarnLOS(Module1.LOSMinutes(D
ataBinder.Eval(Container.DataItem,"vAdmDtTm"))))%>'
Text='<%# DataBinder.Eval(Container, "DataItem.rmDesc")%>'
ID="Label2">
</asp:Label>


The Public functions in the common module (WarnLOS and LOSMinutes) do some
conversions, but I reuse these function in a lot of the pages - so I wanted
to put them in one place - the common module.
THE PROBLEM: I get this error:
Compiler Error Message: BC30451: Name 'Module1' is not declared.
When I try to access the functions from the common module. How do I
declare Module1 from the in-line scripts?
 

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,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top