binding class variable to aspx page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Pasetti

    #1

    binding class variable to aspx page

    I'm having trouble binding/displaying a class variable to
    the display aspx page. Perhaps someone can suggest what I
    am doing wrong.

    ############### ############### #####
    Within the .aspx page I have this:
    ############### ############### #####
    <td><%# p.ParcelName %></td>

    ############### ############### ###############
    Within the code-behind page I have this:
    ############### ############### ###############
    private void Page_Load(objec t sender, System.EventArg s e)
    {
    ParcelBusiness p = new ParcelBusiness( Convert.ToInt32
    (Request.QueryS tring["parcelID"]));
    DataBind();
    }

    p.ParcelName returns the parcel name from the business
    layer in string format. When I attempt to access
    the .aspx page, the following error is generated:

    CS0246: The type or namespace name 'p' could not be found

    Your advice will be greatly appreciated.

    -Andrew


  • James J. Foster

    #2
    Re: binding class variable to aspx page

    You issue is one of scope. The object "p" is only in scope for that method.
    In order to databind within the aspx page, which is a derived class from
    your code-behind class, try moving the ParcelBusiness object to the class
    level, and making it protected (so the derived class can see it).

    [Add in Code-Behind]
    protected ParcelBusiness p;

    [Change In Page_Load]
    p = new Parcel...etc...

    --
    James J. Foster, DotNetCoders


    "Andrew Pasetti" <andrewpasetti@ yahoo.com> wrote in message
    news:0b9801c37b b4$40b7c160$a00 1280a@phx.gbl.. .[color=blue]
    > I'm having trouble binding/displaying a class variable to
    > the display aspx page. Perhaps someone can suggest what I
    > am doing wrong.
    >
    > ############### ############### #####
    > Within the .aspx page I have this:
    > ############### ############### #####
    > <td><%# p.ParcelName %></td>
    >
    > ############### ############### ###############
    > Within the code-behind page I have this:
    > ############### ############### ###############
    > private void Page_Load(objec t sender, System.EventArg s e)
    > {
    > ParcelBusiness p = new ParcelBusiness( Convert.ToInt32
    > (Request.QueryS tring["parcelID"]));
    > DataBind();
    > }
    >
    > p.ParcelName returns the parcel name from the business
    > layer in string format. When I attempt to access
    > the .aspx page, the following error is generated:
    >
    > CS0246: The type or namespace name 'p' could not be found
    >
    > Your advice will be greatly appreciated.
    >
    > -Andrew
    >
    >[/color]


    Comment

    Working...