Page view counter

webcontrols passing variables to other aspx, master pages and webcontrols

Last post 06-17-2008 12:18 AM by Amanda Wang - MSFT. 2 replies.

Sort Posts:

  • webcontrols passing variables to other aspx, master pages and webcontrols

    06-15-2008, 3:20 PM
    • Loading...
    • emmafox
    • Joined on 06-09-2008, 7:28 PM
    • Posts 1
    • Points 2
      

    Hello

                I am developing my site like below; all the pages will have a master page and two webcontrols. The first one will get all the details of the user and the second one will log the user’s footprint.

     

    What I would like to know is how can I make available variables from the UserProfile.aspx to the other two pages.

     

    So in UserProfile.ascx I have a variable strCustomerFirstName = ‘Dave’ how can I access it without using session variables

        

    MasterPage

     

    UserProfile.ascx

     

    Some.aspx

     

    UserFootprint.ascx

     

     

  • Re: webcontrols passing variables to other aspx, master pages and webcontrols

    06-16-2008, 1:49 AM
    Answer
    • Loading...
    • cninjas
    • Joined on 05-29-2007, 7:29 AM
    • Posts 146
    • Points 778

    hi

    you can have a property and set that property in the parent page and make the user control to work accordingly

    http://www.openmymind.net/communication/index.html

    chk this link

    ninjas

  • Re: webcontrols passing variables to other aspx, master pages and webcontrols

    06-17-2008, 12:18 AM
    Answer

    Hi,

    You can try to expose the variable  in the user control, then it can be accessed.

    Below is me sample code:

    1. the user control, expose the variable in the codebheind:

    private string _lbl;
        public string lbl
        {
            get
            {
                return _lbl;
            }
            set
            {
                _lbl = value;
            }
        }

    2. Then expose this user control in the master page's codebehind:

     public ASP.testusercontrol_usercontrols_uc1l_ascx control
        {
            get
            {
                return this.UC1l1;
            }
        }

    UC1l1 is the usercontrol's ID in the master page, ASP.testusercontrol_usercontrols_uc1l_ascx is the type of my usercontrol.

    3. add the @materType directive for the content page:

    <%@ Page Language="C#" MasterPageFile="~/TestUserControl/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="TestUserControl_Default" Title="Untitled Page" %>
    <%@ MasterType VirtualPath="~/TestUserControl/MasterPage.master" %>

    4. Access the usercontrol's variable  in the content page's codebehind:

      ASP.testusercontrol_usercontrols_uc1l_ascx usercontrol = this.Master.control;
      usercontrol.lbl = "this is the content page's message!";

    Hope it helps.

    Amanda Wang
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (3 items)