Monday, March 26, 2012

Passing Values To A User Control

I have seen examples where you can set values in a user control by typing in
the value like te following:
<uc1:MyUserCtrl id="myUserCtrl" ScreenName="User Entry" runat="server" />
So in the case I am populating a variable called "ScreenName" with "User Ent
ry".
Can I not create properties in the main codebehind form and make these prope
rties availble to the usercontrol? I know you can create properties in the
control and make those availble to the main page, but how can you go the oth
er way?
Thanks!"Issac Gomez" <anonymous@.discussions.microsoft.com> wrote in message
news:D7323912-CD68-461C-8DB0-CDC414DD4E8E@.microsoft.com...
> I have seen examples where you can set values in a user control by typing
in the value like te following:
> <uc1:MyUserCtrl id="myUserCtrl" ScreenName="User Entry" runat="server" />
> So in the case I am populating a variable called "ScreenName" with "User
Entry".
> Can I not create properties in the main codebehind form and make these
properties availble to the usercontrol? I know you can create properties in
the control and make those availble to the main page, but how can you go the
other way?
That's the reverse of what you should do. The Page should be in charge, not
the user control. If you want to pass something from the page to the user
control, then have the page set a property of the user control.
--
John Saunders
johnwsaundersiii at hotmail
sure ya can
Make sure to set a public property in the control
From there you should be able to
1) declare the control in the codebehind
2) populate it
myUserCtrl.ScreenName = "User Entry"
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Issac Gomez" <anonymous@.discussions.microsoft.com> wrote in message
news:D7323912-CD68-461C-8DB0-CDC414DD4E8E@.microsoft.com...
> I have seen examples where you can set values in a user control by typing
in the value like te following:
> <uc1:MyUserCtrl id="myUserCtrl" ScreenName="User Entry" runat="server" />
> So in the case I am populating a variable called "ScreenName" with "User
Entry".
> Can I not create properties in the main codebehind form and make these
properties availble to the usercontrol? I know you can create properties in
the control and make those availble to the main page, but how can you go the
other way?
> Thanks!
You can access public property of the main page in usercontrol like this,
DirectCast(Page, <mainpage> ).<publicproperty>
Saravana
Microsoft MVP - ASP.NET
www.extremeexperts.com
"Issac Gomez" <anonymous@.discussions.microsoft.com> wrote in message
news:D7323912-CD68-461C-8DB0-CDC414DD4E8E@.microsoft.com...
> I have seen examples where you can set values in a user control by typing
in the value like te following:
> <uc1:MyUserCtrl id="myUserCtrl" ScreenName="User Entry" runat="server" />
> So in the case I am populating a variable called "ScreenName" with "User
Entry".
> Can I not create properties in the main codebehind form and make these
properties availble to the usercontrol? I know you can create properties in
the control and make those availble to the main page, but how can you go the
other way?
> Thanks!

0 comments:

Post a Comment