Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 7th, 2007, 02:42 PM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default Binding can't see BL method, even with Namespace

I have an aspx page that I am trying to bind to a method in a BL class I have--but the binding can't recognize the class--even when I include it in the code-behind page. I basically had to create a method in the code behind page that called the class. Here is the code that works:

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="awards.aspx.vb" Inherits="awards" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    <div style="position:relative; min-height:500px;" >
        <div style="position:absolute; top:0; bottom:0; left:0; margin-left:5px; margin-top:5px;">
            <asp:Image ID="Image1" runat="server" ImageUrl="Site_Images/YosemiteFalls.jpg" Width="400px"/>
        <div style="margin: 5px 5px 5px 440px; min-height:720px; padding-top:4px">
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="GetLocationsDataSource" AllowPaging="True" GridLines="None" HorizontalAlign="NotSet" EditRowStyle-VerticalAlign="NotSet" ShowHeader="false" PageSize="10" DataKeyNames="awardID">
                        <asp:Label ID="LocationLabel1" runat="server" Text='<%# Eval("Location") %>' Font-Bold="true"></asp:Label>
                        <asp:GridView ID="GridView1" AutoGenerateColumns="False" runat="server" DataSource='<%# BehindGetPlaceListPerAward(CType(Eval("AwardID"), Integer)) %>' GridLines="None" ShowHeader="false">
                        <asp:BoundField DataField="year" DataFormatString="{0}:" />
                        <asp:BoundField DataField="title" />
            <RowStyle VerticalAlign="Top" />

<asp:ObjectDataSource ID="GetLocationsDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetList" TypeName="Searing.SunArtSite.Bll.AwardsManager"></asp:ObjectDataSource>

Here's the code behind page:

Imports Searing.SunArtSite.BO
Imports Searing.SunArtSite.Bll

Partial Class awards
    Inherits System.Web.UI.Page

    Protected Function BehindGetPlaceListPerAward(ByVal id As Integer) As PlaceList
        Return PlaceManager.GetPlaceListPerAward(id)
    End Function

End Class

Why couldn't I just call PlaceManager.GetPlaceListPerAward(id) directly from the aspx page rather than calling BehindGetPlaceListPerAward(id) to only have it do it.

Basically..why does the code-behind page see the method in the class PlaceManager (Namespace rsearing.sunartsite.BLL) but the "front-side" aspx page can't see it?


Old July 9th, 2007, 08:26 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

Rob, I think this has to do with the imports. Yes, you have imported the BLL in your codebehind, but the page only inherits from that code-behind class. In order to "see" your BLL classes from inline code in the markup, you need to import the appropriate namespace in the markup page.

HOWEVER, this being said... I would stick with the way you have it. Why? Because you would be coupling "unchecked" code to an external resource. You would have a direct reference from non pre-compiled code in the markup to a class library outside of the web app itself.

If you make the markup code call a method directly on the page, and have the page class method call the BLL, you ensure that if you change the BLL class you'll get a compile time break which you can fix right away instead of a break later on in run-time. This is generally a better practice.


Similar Threads
Thread Thread Starter Forum Replies Last Post
About Namespace cfanllm C# 2005 5 April 13th, 2007 08:15 AM
Namespace ~Bean~ Classic ASP Basics 2 June 3rd, 2005 02:31 PM
namespace Ibn_Aziz C# 2 December 25th, 2003 05:41 AM
namespace within namespace Bill Crawley XML 1 December 11th, 2003 10:59 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.