开发者

asp.net use class object on form

开发者 https://www.devze.com 2022-12-18 07:38 出处:网络
I am creating an obje开发者_StackOverflow社区ct at server side of an aspx (test.cs) page from a class(asp.net 2.0 C#)

I am creating an obje开发者_StackOverflow社区ct 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...


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消