Thursday, March 29, 2012

Pass parameters to User Control

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
BenHi 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
"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> 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
>
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.
With the best wishes,
Shaul Feldman
"Ben" <Ben@.nospam.com> wrote in message
news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
> 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
>
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="http://pics.10026.com/?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
"Shaul Feldman" <sfeldman@.writeme.com> wrote in message
news:e$%23BiHkJEHA.3944@.tk2msftngp13.phx.gbl...
> 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.
> --
> With the best wishes,
> Shaul Feldman
> "Ben" <Ben@.nospam.com> wrote in message
> news:u4tZ4ShJEHA.1764@.TK2MSFTNGP12.phx.gbl...
ASPX
>
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
"Lynne K." <ltgaer@.assurity.com> wrote in message
news:7a65e5b4.0405110605.559f0d2d@.posting.google.com...
> 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.
> "Shaul Feldman" <sfeldman@.writeme.com> wrote in message
news:<e$#BiHkJEHA.3944@.tk2msftngp13.phx.gbl>...
you
case
ASPX

0 comments:

Post a Comment