views:

21

answers:

2

Hello , I am creating an object at server side of an aspx (test.cs) page from a class (asp.net 2.0 C#)

public partial class Vendor_VendorUsedTicketsPopup : System.Web.UI.Page
{
    ReportInvoice _objReportInvoice = new ReportInvoice();

    protected void Page_Load(object sender, EventArgs e)
    {
        _objReportInvoice.ReportId = 1;
    }
}

as you see above before Page Load I am creating a new ReportInvoice object and on page load I am setting property ReportId to 1

On test.aspx I want to use the ReportId value bu using the _objReportInvoice object like below

<div><% _objReportInvoice.ReportId; %></div>

But when I build the site I get the error *The name '_objReport' does not exist in the current context*

I know that I can create a public integer for ReportId above Page_Load and use it on aspx page. That works fine , but I want to use class object properties on aspx page.

What is the way of doing sth like that ?

Thanks...

A: 

You need a = sign in there to print it to the page:

<div><%= _objReportInvoice.ReportId; %></div>

However, I would suggest just using a Literal or Label control there and then setting it's text to the ReportID property in the code behind. Inline code like that can make your HTML messy.

ryanulit
Thanks for the answer it works fine now.Also ReportInvoice object must be declared as publicpublic ReportInvoice _objReportInvoice = new ReportInvoice();
A: 

Remember that your .ASPX markup page inherits from the codebehind class.

This means that unless you declare your field as protected or public, the .aspx will not have access to your field.

You need to add an access modifier to your field to make it non-private.

womp