Pass parameters to User Control

Discussion in 'ASP .Net' started by Ben, Apr 19, 2004.

  1. Ben

    Ben Guest

    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
     
    Ben, Apr 19, 2004
    #1
    1. Advertising

  2. 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

    "Ben" <> wrote in message
    news:...
    > 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
    >
    >
     
    Ashish M Bhonkiya, Apr 19, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Shaul Feldman, Apr 19, 2004
    #3
  4. Ben

    Ben Guest

    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

    "Shaul Feldman" <> wrote in message
    news:e$%...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
     
    Ben, Apr 22, 2004
    #4
  5. Ben

    Lynne K. Guest

    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" <> wrote in message news:<e$#>...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >
     
    Lynne K., May 11, 2004
    #5
  6. Ben

    David Jessee Guest

    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." <> wrote in message
    news:...
    > 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" <> wrote in message

    news:<e$#>...
    > > 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" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >
     
    David Jessee, May 12, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Henke
    Replies:
    3
    Views:
    3,558
  2. Replies:
    2
    Views:
    6,572
    Joshua Flanagan
    Feb 28, 2005
  3. keith
    Replies:
    9
    Views:
    2,117
    Graham Underwood
    Aug 8, 2008
  4. Jill Graham

    How to pass parameters to a user control

    Jill Graham, Jun 8, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    470
    Jonathan
    Jun 18, 2004
  5. hmikki
    Replies:
    1
    Views:
    144
    Nathan Sokalski
    Oct 19, 2007
Loading...

Share This Page