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

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,
Who is Participating?
rajaloysiousConnect With a Mentor Commented:
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>

YurichConnect With a Mentor Commented:
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...

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.