HTML Controls and User controls

Discussion in 'ASP .Net' started by trinitypete, Jun 25, 2003.

  1. trinitypete

    trinitypete Guest

    I have a user control that is basically a login dialogue.
    If I add the user control to webpage1, can I access the
    properties directly from C# codebehind, or do I have to
    access the properties from HTML behind webpage1.

    Thanks in advance. Pete
     
    trinitypete, Jun 25, 2003
    #1
    1. Advertising

  2. trinitypete

    trinitypete Guest

    Webpage1 is a standard ASP.NET webform which contains the
    user control. I know I can access properties of the user
    control via the HTML of webpage1 i.e.
    <uc1:LoginUserControl id="LoginUserControl1"
    property1="Hello" property2="Goodbye"
    runat="server"></uc1:LoginUserControl>

    but is it possible to access the properties from webpage1
    code behind page.

    Hope this is a little clearer.
    Pete.

    >-----Original Message-----
    >What exactly is "webpage1?"
    >
    >HTH,
    >
    >Kevin Spencer
    >Microsoft FrontPage MVP
    >Internet Developer
    >http://www.takempis.com
    >Big things are made up of
    >lots of Little things.
    >
    >"trinitypete" <> wrote in message
    >news:0a9501c33b1f$732d7610$...
    >> I have a user control that is basically a login

    dialogue.
    >> If I add the user control to webpage1, can I access the
    >> properties directly from C# codebehind, or do I have to
    >> access the properties from HTML behind webpage1.
    >>
    >> Thanks in advance. Pete

    >
    >
    >.
    >
     
    trinitypete, Jun 25, 2003
    #2
    1. Advertising

  3. trinitypete

    Ryan Fiorini Guest

    Yes It is possible. Here is the code to do it.

    Dim _myControl As Control = Page.FindControl("UserControlName")
    Dim _myControlType As Type = _myControl.GetType()
    Dim _myControl_Property As PropertyInfo =
    _myControlType.GetProperty("PROPERTYNAME")

    sTemp = _myControl_Property.GetValue(_myControl, Nothing)


    Hope this helps.

    Ryan


    "trinitypete" <> wrote in message
    news:0c6201c33b29$2351b0c0$...
    > Webpage1 is a standard ASP.NET webform which contains the
    > user control. I know I can access properties of the user
    > control via the HTML of webpage1 i.e.
    > <uc1:LoginUserControl id="LoginUserControl1"
    > property1="Hello" property2="Goodbye"
    > runat="server"></uc1:LoginUserControl>
    >
    > but is it possible to access the properties from webpage1
    > code behind page.
    >
    > Hope this is a little clearer.
    > Pete.
    >
    > >-----Original Message-----
    > >What exactly is "webpage1?"
    > >
    > >HTH,
    > >
    > >Kevin Spencer
    > >Microsoft FrontPage MVP
    > >Internet Developer
    > >http://www.takempis.com
    > >Big things are made up of
    > >lots of Little things.
    > >
    > >"trinitypete" <> wrote in message
    > >news:0a9501c33b1f$732d7610$...
    > >> I have a user control that is basically a login

    > dialogue.
    > >> If I add the user control to webpage1, can I access the
    > >> properties directly from C# codebehind, or do I have to
    > >> access the properties from HTML behind webpage1.
    > >>
    > >> Thanks in advance. Pete

    > >
    > >
    > >.
    > >
     
    Ryan Fiorini, Jun 25, 2003
    #3
  4. trinitypete

    trinitypete Guest

    It worked a treat - Thanks.

    >-----Original Message-----
    >Yes It is possible. Here is the code to do it.
    >
    > Dim _myControl As Control = Page.FindControl

    ("UserControlName")
    > Dim _myControlType As Type =

    _myControl.GetType()
    > Dim _myControl_Property As PropertyInfo =
    >_myControlType.GetProperty("PROPERTYNAME")
    >
    > sTemp = _myControl_Property.GetValue

    (_myControl, Nothing)
    >
    >
    >Hope this helps.
    >
    >Ryan
    >
    >
    >"trinitypete" <> wrote in message
    >news:0c6201c33b29$2351b0c0$...
    >> Webpage1 is a standard ASP.NET webform which contains

    the
    >> user control. I know I can access properties of the user
    >> control via the HTML of webpage1 i.e.
    >> <uc1:LoginUserControl id="LoginUserControl1"
    >> property1="Hello" property2="Goodbye"
    >> runat="server"></uc1:LoginUserControl>
    >>
    >> but is it possible to access the properties from

    webpage1
    >> code behind page.
    >>
    >> Hope this is a little clearer.
    >> Pete.
    >>
    >> >-----Original Message-----
    >> >What exactly is "webpage1?"
    >> >
    >> >HTH,
    >> >
    >> >Kevin Spencer
    >> >Microsoft FrontPage MVP
    >> >Internet Developer
    >> >http://www.takempis.com
    >> >Big things are made up of
    >> >lots of Little things.
    >> >
    >> >"trinitypete" <> wrote in message
    >> >news:0a9501c33b1f$732d7610$...
    >> >> I have a user control that is basically a login

    >> dialogue.
    >> >> If I add the user control to webpage1, can I access

    the
    >> >> properties directly from C# codebehind, or do I have

    to
    >> >> access the properties from HTML behind webpage1.
    >> >>
    >> >> Thanks in advance. Pete
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >
     
    trinitypete, Jun 25, 2003
    #4
  5. Your CodeBehind Page should have a reference to the control if you used the
    tag you mentioned in your reply. You can therefore access the properties of
    the object in your CodeBehind (using its' ID) without any problem.

    HTH,

    Kevin Spencer
    Microsoft FrontPage MVP
    Internet Developer
    http://www.takempis.com
    Big things are made up of
    lots of Little things.

    "trinitypete" <> wrote in message
    news:0c6201c33b29$2351b0c0$...
    > Webpage1 is a standard ASP.NET webform which contains the
    > user control. I know I can access properties of the user
    > control via the HTML of webpage1 i.e.
    > <uc1:LoginUserControl id="LoginUserControl1"
    > property1="Hello" property2="Goodbye"
    > runat="server"></uc1:LoginUserControl>
    >
    > but is it possible to access the properties from webpage1
    > code behind page.
    >
    > Hope this is a little clearer.
    > Pete.
    >
    > >-----Original Message-----
    > >What exactly is "webpage1?"
    > >
    > >HTH,
    > >
    > >Kevin Spencer
    > >Microsoft FrontPage MVP
    > >Internet Developer
    > >http://www.takempis.com
    > >Big things are made up of
    > >lots of Little things.
    > >
    > >"trinitypete" <> wrote in message
    > >news:0a9501c33b1f$732d7610$...
    > >> I have a user control that is basically a login

    > dialogue.
    > >> If I add the user control to webpage1, can I access the
    > >> properties directly from C# codebehind, or do I have to
    > >> access the properties from HTML behind webpage1.
    > >>
    > >> Thanks in advance. Pete

    > >
    > >
    > >.
    > >
     
    Kevin Spencer, Jun 25, 2003
    #5
  6. Sorry trinitypete,

    I misunderstood your question, and neglected to observe that you were
    talking about a User Control instead of a Server Control. Handling the User
    Control from your CodeBehind is a bit trickier than a Server Control. The
    following MSDN article should help:

    http://msdn.microsoft.com/library/d...guide/html/cpconexposingpageletproperties.asp

    HTH,

    Kevin Spencer
    Microsoft FrontPage MVP
    Internet Developer
    http://www.takempis.com
    Big things are made up of
    lots of Little things.

    "trinitypete" <> wrote in message
    news:017901c33b31$40806b20$...
    > Kevin,
    >
    > Now I am intrigued. The HTML used in the webpage1 has the
    > tags etc as follows:
    >
    > <%@ Register TagPrefix="uc1" TagName="LoginUserControl"
    > Src="LoginUserControl.ascx" %>
    > <uc1:LoginUserControl id="LoginUserControl1"
    > runat="server"></uc1:LoginUserControl>
    >
    > I tried to access the control using LoginUserControl1 but
    > intellisense didn't pick it up. I cant find any references
    > to the control in webpage1 code behind? Does the Tagprefix
    > come into it at all - ie is it a namespace issue?
    >
    > I have tried recreating the project from scratch but there
    > is still no reference in webpage1 code behind?
    >
    > >-----Original Message-----
    > >Your CodeBehind Page should have a reference to the

    > control if you used the
    > >tag you mentioned in your reply. You can therefore access

    > the properties of
    > >the object in your CodeBehind (using its' ID) without any

    > problem.
    > >
    > >HTH,
    > >
    > >Kevin Spencer
    > >Microsoft FrontPage MVP
    > >Internet Developer
    > >http://www.takempis.com
    > >Big things are made up of
    > >lots of Little things.
    > >
    > >"trinitypete" <> wrote in message
    > >news:0c6201c33b29$2351b0c0$...
    > >> Webpage1 is a standard ASP.NET webform which contains

    > the
    > >> user control. I know I can access properties of the user
    > >> control via the HTML of webpage1 i.e.
    > >> <uc1:LoginUserControl id="LoginUserControl1"
    > >> property1="Hello" property2="Goodbye"
    > >> runat="server"></uc1:LoginUserControl>
    > >>
    > >> but is it possible to access the properties from

    > webpage1
    > >> code behind page.
    > >>
    > >> Hope this is a little clearer.
    > >> Pete.
    > >>
    > >> >-----Original Message-----
    > >> >What exactly is "webpage1?"
    > >> >
    > >> >HTH,
    > >> >
    > >> >Kevin Spencer
    > >> >Microsoft FrontPage MVP
    > >> >Internet Developer
    > >> >http://www.takempis.com
    > >> >Big things are made up of
    > >> >lots of Little things.
    > >> >
    > >> >"trinitypete" <> wrote in message
    > >> >news:0a9501c33b1f$732d7610$...
    > >> >> I have a user control that is basically a login
    > >> dialogue.
    > >> >> If I add the user control to webpage1, can I access

    > the
    > >> >> properties directly from C# codebehind, or do I have

    > to
    > >> >> access the properties from HTML behind webpage1.
    > >> >>
    > >> >> Thanks in advance. Pete
    > >> >
    > >> >
    > >> >.
    > >> >

    > >
    > >
    > >.
    > >
     
    Kevin Spencer, Jun 25, 2003
    #6
  7. trinitypete

    trinitypete Guest

    Thanks Kevin,

    Will research link.

    >-----Original Message-----
    >Sorry trinitypete,
    >
    >I misunderstood your question, and neglected to observe

    that you were
    >talking about a User Control instead of a Server Control.

    Handling the User
    >Control from your CodeBehind is a bit trickier than a

    Server Control. The
    >following MSDN article should help:
    >
    >http://msdn.microsoft.com/library/default.asp?

    url=/library/en-
    us/cpguide/html/cpconexposingpageletproperties.asp
    >
    >HTH,
    >
    >Kevin Spencer
    >Microsoft FrontPage MVP
    >Internet Developer
    >http://www.takempis.com
    >Big things are made up of
    >lots of Little things.
    >
    >"trinitypete" <> wrote in message
    >news:017901c33b31$40806b20$...
    >> Kevin,
    >>
    >> Now I am intrigued. The HTML used in the webpage1 has

    the
    >> tags etc as follows:
    >>
    >> <%@ Register TagPrefix="uc1" TagName="LoginUserControl"
    >> Src="LoginUserControl.ascx" %>
    >> <uc1:LoginUserControl id="LoginUserControl1"
    >> runat="server"></uc1:LoginUserControl>
    >>
    >> I tried to access the control using LoginUserControl1

    but
    >> intellisense didn't pick it up. I cant find any

    references
    >> to the control in webpage1 code behind? Does the

    Tagprefix
    >> come into it at all - ie is it a namespace issue?
    >>
    >> I have tried recreating the project from scratch but

    there
    >> is still no reference in webpage1 code behind?
    >>
    >> >-----Original Message-----
    >> >Your CodeBehind Page should have a reference to the

    >> control if you used the
    >> >tag you mentioned in your reply. You can therefore

    access
    >> the properties of
    >> >the object in your CodeBehind (using its' ID) without

    any
    >> problem.
    >> >
    >> >HTH,
    >> >
    >> >Kevin Spencer
    >> >Microsoft FrontPage MVP
    >> >Internet Developer
    >> >http://www.takempis.com
    >> >Big things are made up of
    >> >lots of Little things.
    >> >
    >> >"trinitypete" <> wrote in message
    >> >news:0c6201c33b29$2351b0c0$...
    >> >> Webpage1 is a standard ASP.NET webform which contains

    >> the
    >> >> user control. I know I can access properties of the

    user
    >> >> control via the HTML of webpage1 i.e.
    >> >> <uc1:LoginUserControl id="LoginUserControl1"
    >> >> property1="Hello" property2="Goodbye"
    >> >> runat="server"></uc1:LoginUserControl>
    >> >>
    >> >> but is it possible to access the properties from

    >> webpage1
    >> >> code behind page.
    >> >>
    >> >> Hope this is a little clearer.
    >> >> Pete.
    >> >>
    >> >> >-----Original Message-----
    >> >> >What exactly is "webpage1?"
    >> >> >
    >> >> >HTH,
    >> >> >
    >> >> >Kevin Spencer
    >> >> >Microsoft FrontPage MVP
    >> >> >Internet Developer
    >> >> >http://www.takempis.com
    >> >> >Big things are made up of
    >> >> >lots of Little things.
    >> >> >
    >> >> >"trinitypete" <> wrote in message
    >> >> >news:0a9501c33b1f$732d7610$...
    >> >> >> I have a user control that is basically a login
    >> >> dialogue.
    >> >> >> If I add the user control to webpage1, can I

    access
    >> the
    >> >> >> properties directly from C# codebehind, or do I

    have
    >> to
    >> >> >> access the properties from HTML behind webpage1.
    >> >> >>
    >> >> >> Thanks in advance. Pete
    >> >> >
    >> >> >
    >> >> >.
    >> >> >
    >> >
    >> >
    >> >.
    >> >

    >
    >
    >.
    >
     
    trinitypete, Jun 26, 2003
    #7
    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. Axel Dahmen
    Replies:
    1
    Views:
    542
    Teemu Keiski
    Nov 12, 2003
  2. Mark
    Replies:
    1
    Views:
    437
    Hermit Dave
    Sep 13, 2004
  3. Faizan Ahmed
    Replies:
    1
    Views:
    309
    John Saunders
    Jan 4, 2005
  4. Faizan Ahmed
    Replies:
    1
    Views:
    389
    John Saunders
    Jan 4, 2005
  5. Adam Akhtar
    Replies:
    9
    Views:
    590
    Florian Gilcher
    Aug 16, 2008
Loading...

Share This Page