Putting/passing/Retriving  a value From Aspx page into an ascx (user control) (URGENT)

Posted on 2005-04-11
Last Modified: 2010-04-16

Hello everyone,

I have a question regarding Aspx and Ascx pages. Currently I have webform which has a usercontrol say "X.ascx"
On load of the web form(aspx) I have a particualr "UserId"  which has  been passed into this page from a differnt page , I would now like to pass this variable(its value actually) into the usercontrol which then retrives values depending on the UserID and pouplates drop downs and does some other stuff  .

It sounds fairly smiple ..but i need to get this pretty quickly .

Hoping that some one can help me out quickly,
Question by:Ashwin_shastry
    LVL 8

    Accepted Solution

    In the user control create a public property called UserId

    private int _UserId; // class level variable

    public int UserId
          get{return _UserId;}
          set{_UserId= value;}
    XControl.UserId =<whatever>

    LVL 21

    Assisted Solution

    you'll have to create manually a protected instance of your web control in your web form cs file, where you're loading, it since it's not added automatically:

    protected X XControl;

    Be very careful - even if you "create" it your selft, actually you don't...
    1. protected - must be, otherwise will throw exception
    2. X - that's your "X.ascx" file
    3. XControl - must be exactly the name of the control your dropped on your form, won't work otherwise

    then do as raja suggests...

    LVL 21

    Expert Comment

    I would say that the question has been answered in full and the points should be split between rajaloysious and me.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    729 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

    20 Experts available now in Live!

    Get 1:1 Help Now