Pass parameters to User Control

B

Ben

Hi

I am using a User Control which is referenced by an ASPX page.

How can I pass a string parameter to the user control, from the base ASPX
page.

Thanks

Ben
 
A

Ashish M Bhonkiya

Hi Ben,

Create a public method in the usercontrol and access the same from the aspx
page.

Ex:

Code in myusercontrol.ascx.cs
public void PublicMethodInUsercontrol(string valuetopasstocontrol)
{
privatevariable = valuetopasstocontrol;
}

Code in the aspx page.

usercontrolinstance.PublicMethodInUsercontrol("MyValueFromPage");



HTH
Regards
Ashish M Bhonkiya
 
S

Shaul Feldman

For this purpose I used to create properties (in user control). This way you
can also pass parameters from aspx file (html).
You can access Session to retrieve values. There're plenty of ways. In case
you need some code, I'll try to post.
 
B

Ben

Sorry for the delay in replying:

I have heard that you can use this method to pass the parameter:

<%@Register tagprefix="CodeLib" Tagname="usrMain" src="usrMain.ascx" %>

<CodeLib:usrMain bodyData="usrText.ascx" linksPage="NoLinks"
requireSecure="False" runat="server" ID="usrMain"/>

But the problem is that I cannot seem to extract the data on the ASCX page

Thanks Ben
 
L

Lynne K.

Help! I have an aspx that loads the ascx with parameters in a
placeholder as textboxes. On my postback I can't get the values out
of the textboxes. They are still on the screen so I'm sure they are
there.

I'm having a hard time. I've been told they should just be there.
aspx
ascx
ascxwp

The ascxwp is the user control that holds the textboxes.

I assume someone has figured this out. We have 3 asp programmers and
we are all stumped.
 
D

David Jessee

Implement Properties inside of your UserControl
e.g.

Public Property FirstName() as String
Get
Return txtFirstName.text
End Get
Set (value as String)
txtFirstName.text=value
end set
end property

Then just access the properties
 

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,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top