How to access a control from another web pages code behind file.

Suppose I have two web pages. "Customers.aspx", and "Scheduling.aspx". Suppose I have a textbox control, or a checkbox control on page  "Customers.aspx". Suppose these values are named  txtCustName, chkAgeGroupBox. I can easily access these two controls from the C# code behind file Customers.aspx.cs. However I need to access these control values from the code behind file "Scheduling.aspx.cs". How can I do that?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Najam UddinCommented:
Well, I am not sure why would want to do it, if you explain a bit why part I can tell you how part
I think this is cross page posting.

My pages has a Master page.

Html Main.aspx
      <script type="text/javascript">
          function showReadMessage(inURL) {
	        popMessage =, "ReadMessageWindow", "location=YES, status=NO, scrollbars=NO, resizable, directories=NO, height=650, width=500");
        	popMessage.document.title = "";

 <asp:TextBox ID="txtCustomerID" runat="server" Width="78px" AutoPostBack="True" 

<asp:Button ID="btnLookup" runat="server" Text="Look Up"  OnClientClick="javascript:showReadMessage('LookupCustomer.aspx')"  PostBackUrl="~/Web/ISO/CutterGrind/NewCutterGrind.aspx" />

Open in new window

    protected void txtCustomerID_TextChanged(object sender, EventArgs e)

        string SQLCmd = "Select [name] from address where id = @CustomerID";
        ArrayList mySqlParameters = new ArrayList();
        mySqlParameters.Add(new SqlParameter("@CustomerId", txtCustomerID.Text.Trim()));

        clsCommonCode myCC = new clsCommonCode();
        string strCName = myCC.GetSingleValue(SQLCmd, mySqlParameters, Global.strP21Connection);

        if (strCName.Trim() == "")
            txtCustomerName.Text = "Customer Not Found";
            txtCustomerName.Text = strCName;

Open in new window

LookupCustomer.aspx (page 2) (its just a gridview)
<%@ PreviousPageType VirtualPath="~/Web/ISO/CutterGrind/NewCutterGrind.aspx" %>

Open in new window

  protected void gvSearchResults_SelectedIndexChanged(object sender, EventArgs e)
        string strValue = gvSearchResults.SelectedValue.ToString();

        if (PreviousPage != null)
            Control placeHolder = PreviousPage.Controls[0].FindControl("MainContent");
            TextBox SourceTextBox = (TextBox)placeHolder.FindControl("txtCustomerID");

            if (SourceTextBox != null)
                SourceTextBox.Text = strValue;



Open in new window

Basically, On Main.aspx there is a CustomerID textbox and a Lookup Button.  They click the button to open via javascript a popup window that sets the asp Button postbackUrl.

on the LookupCustomer.aspx its just a Gridview that pulls a list of customers from a database.  They click on the customer they want.   The gridview  selectedIndexChanged event code behind checks Page.PreviousPage (It is set on the LookupCustomer.aspx @ PreviousPageType) for a null.  If not null its Finds the Textbox on the PreviousPage then sets the value on the PreviousPage.

The important thing is to set the PreviousPage.

I hopes this helps you out.
brgdotnetcontractorAuthor Commented:
My two pages are pretty much independent of each other. They do not depend on each other. However I need to grab the controls from another page, and get the value stored in that control. I am not using Master pages or User controls. Just simple controls.
if you are not transferring between those two pages, can you store the  txtCustName, chkAgeGroupBox values in session and access it ?.

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
What I wrote has nothing to do with Master pages/ User controls.  I also use normal controls.

So the data on one page is not dependent on another page.  not like my Customer Lookup?

So if they goto Scheduling.aspx  and bypassing Customers.aspx, then you don't have the  txtCustName and chkAgeGroupBox controls filled in.  

Let me know if I'm on the wrong path.    Customer.aspx you fill in the customer info, CustName/AgeGroup.   Then click on Scheduling to schedule something but you need the CustName/AgeGroup for that information.    

1) Do the PreviousPage stuff.
2) Assign the CustName/AgeGroup to Session Variables.
   To put. 
     Session["CustName"] = txtCustName.Text; 
    Session["AgeGroup"] = chkAgeGroupBox.Checked;

 to retrieve.
    strCustName = Session["CustName"] .ToString();
    boolAgeGroup = (Bool)Session["CustName"] .ToString();


Open in new window

3) Save the Customer in DB,  Pass Customer Name to Scheduling.aspx via QueryString.
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.