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,
Cheers
Ashwin
Ashwin_shastryAsked:
Who is Participating?
 
rajaloysiousConnect With a Mentor Commented:
In the user control create a public property called UserId

"X.ascx"
private int _UserId; // class level variable

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

cheers
0
 
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...

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

regards,
yurich
0
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.