Passing parameters to user controls

A

Akira

Hello.
I'm having problem with passing parameters from .aspx file to user
control.
Could anyone tell me how to pass parameters from .aspx file to user
control(.ascx) and how to recieve parameters at .ascx?
Thank you for your help!
 
C

Cowboy \(Gregory A. Beamer\)

Open the CodeBehind file and add the user control to the controls
collection. Not sure why, but, by default, a user control is placed on the
page but never given a corresponding line in the CodeBehind file.

Dim NameOfControlOnPage As MyControl
protected MyControl NameOfControlOnPage;

You can see the lines of other controls in your CodeBehind, so the above
templates are suspect. Once you do this, you will be able to use:

NameOfControlOnPage.PropertyOne = "";

to set values.
 
K

Karl Seguin

use properties...or public fields :)

user control:

private _ValueID as integer
Public Property ValueID as integer
Get
return _ValueID
ENd Get
Set (byval value as integer)
_ValueID = value
end set
end property

From within the user control you can simply refer to "ValueID" from
thereonin to get the value that was assigned to it by the parent.


Parent:
Two methods
<control:name runat="server" id="cntrl" ValueID=3 />

in codebehind
cntrl.ValueID = 3


Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top