Get value from aspx page and use in ascx page

Can any tell me how to do the following.

I have a variable strTest = "A" in an aspx page
I want to retrieve the value of strTest in an ascx page and put the value into a variable called strRetrievedTest.

can anyone tell me how to do that.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi  BeginningWebDesign,

To use any variable of aspx or ascx page into other ascx or aspx page you have create property into calling ascx or aspx.
step 1 : Using Set property you can set variable value
step 2 : Using Get property you can get variable value from page.
You can create property and retrive variable value from other ascx or aspx page as below:

namespace NameSpaceName
public class ASPXClass
public string  strTest = "A";

#region Property
                                public string ReturnStrTestValue
                        strTest =value; //Set strTest value on each call of ascx page.
                        return strTest;  //Return strTest value on each call of ascx page.


code of ascx page
namespace NameSpaceForAscxPage
public class ASCXClass
#region Functions
public void GetStrTestValue()
//Create object of aspx page
ASPXClass ObjASPXPage;

//Then use public property "ReturnStrTestValue" of ASPX Page.
//Code as below:
ObjASPXPage = (ASPXClass)LoadControl("ASPXClass.aspx");
Response.write("StrTest Value of ASPX Class is" + ObjASPXPage.ReturnStrTestValue );

I hope this is what you are looking for.
All the very best.
Alpesh Patel.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BeginningWebDesignAuthor Commented:
Hi Alpesh

Hope you had a good new year, I've tried your code and cannot get the ascx page to work.

This is my section of code.
I assumed that a master page would react the same as a ascx page, but I must me wrong.

public partial class header_header : System.Web.UI.MasterPage
    protected void Page_Load(object sender, EventArgs e)


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.