lorena Posted February 20, 2006 Posted February 20, 2006 I have several functions common to almost all of the pages in my web application. According to what I have read (and this is the first time I have tried to do this), I should be able to create a class that contains the function(s) and access it from within my code (either code-behind or .aspx) Here is the class code: Public Class mreqFunctions Public Shared Function showShortDate(ByVal aDate As Object) If Not IsDBNull(aDate) Then Return aDate.ToShortDateString End If End Function End Class and I am using it to display dates in the ItemTemplate of a datagrid. I tried two different ways: <ItemTemplate> <asp:Label ID="lblReqCompDate" Runat="server" text='<%=mreqFunctions.showShortDate(DataBinder.Eval(Container.DataItem,"requested_comp_date")) %>' /> </ItemTemplate> (just displays blank field - no error but no date either) And this way: <ItemTemplate> <asp:Label ID="lblReqCompDate" Runat="server" text='<%#mreqFunctions.showShortDate(DataBinder.Eval(Container.DataItem,"requested_comp_date")) %>' /> </ItemTemplate> Which gives me this error:BC30451: Name 'mreqFunctions' is not declared What do I need to do to declare the function? I am using VS 2003. I am really confused and would appreciate any help Quote
lorena Posted February 20, 2006 Author Posted February 20, 2006 Okay - No longer confused I forgot to add a reference to the class in my code behind. It all makes sense now - and it works :D Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.