Pass variable from 1 section of code to another

Posted on 2005-04-26
Last Modified: 2010-04-16
Can anyone tell me how I can get the value of strOrderNumber to display in lblDisplayOrderNumber.Text
lblDisplayOrderNumber is in a different panel to strOrderNumber.


private void btnProceed_Click(object sender, System.EventArgs e)
// code
strOrderNumber = "Order number" + " " + sqlComRetrieveOrderNumber.Parameters["@RETURN_VALUE"].Value.ToString();

private void btnCheckDetails_Click(object sender, System.EventArgs e)
lblDisplayOrderNumber.Text = strOrderNumber;
Question by:BeginningWebDesign
    LVL 8

    Expert Comment

    what you mean?-->lblDisplayOrderNumber is in a different panel to strOrderNumb
    LVL 1

    Accepted Solution

    When you say that lblDisplayOrderNumber is in a different panel to strOrderNumber, does that mean that they are in a different form or the same form?

    If they are on the same form you would just need to make strOrderNumber a class variable.

    If they are on a different form, you could create a property for your strOrderNumber like so:

    public StrOrderNumber
        return strOrderNumber;
        strOrderNumber = value;

    you would need to add a reference to the form that has the strOrderNumber in the constructor - like so:

    form2(form1 f1)
      //class logic
      f1.StrOrderNumber = value;

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now