User Control - setting properties

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default User Control - setting properties

    Don't quite get it.

    User control has a label in a html table and I want to set the text property
    of the label from code behind. (MyLabel)

    <%@ Register TagPrefix="MCP" TagName="TOPMENU" src="TopMenu.ascx" %>
    <HTML>



    FORM....
    <MCP:TOPMENU id="TopMenu1" runat="server"></MCP:TOPMENU>


    CODE BEHIND...PAGE LOAD

    ??? MyLabel.Text="Something"

    Can't see the label object in the code behind... Why not? How do I get to
    it?


    John Carnahan Guest

  2. Similar Questions and Discussions

    1. Setting web custom control properties at design time
      I am developing a Web custom control whose properties (such as text) I would like to map to other control properties (such as textbox1.text) or...
    2. setting control properties based on another control
      I have a grid, a label within the grid, and another grid within the grid. I want the label to be the same size as the child grid, how would I do...
    3. Setting Control Properties with a Control Builder
      I have a control that requires a custom ControlBuilder to parse certain child tags as controls, but I also want to use other tags to set properties....
    4. User Control properties
      Hi all, I'm a total newbie, so this might be stupid... Anyway, I've created an expanding tree of categories control, based on DataList. It works...
    5. Setting Properties on a user control on from the Parent Page
      "Eric Elliston" <eelliston@neighborhoodamerica.com> wrote in message news:OiPSIL2ZDHA.1492@TK2MSFTNGP12.phx.gbl... All and control end the
  3. #2

    Default Re: User Control - setting properties

    > User control has a label in a html table and I want to set the text property
    > of the label from code behind. (MyLabel)
    >
    > <%@ Register TagPrefix="MCP" TagName="TOPMENU" src="TopMenu.ascx" %>
    > <HTML>
    >
    >
    > FORM....
    > <MCP:TOPMENU id="TopMenu1" runat="server"></MCP:TOPMENU>
    >
    >
    > CODE BEHIND...PAGE LOAD
    >
    > ??? MyLabel.Text="Something"
    >
    > Can't see the label object in the code behind... Why not? How do I get to
    > it?
    John, give the User Control a public string property, like MyLabelText.
    Then in the Page_Load event of the User Control, set its Label's Text
    property to the value of the MyLabelText property. In the ASP.NET Web
    page's code behind class, set the User Control's MyLabelText like so:

    TopMenu1.MyLabelText = "Foo"

    (You'll need to have manually added in a reference to TopMenu1 in your
    class, like:

    Protected TopMenu1 as TopMenu
    )

    For more information, be sure to read:

    An Extensive Examination Of User Controls
    [url]http://msdn.microsoft.com/asp.net/using/building/webcontrols/default.aspx?pull=/library/en-us/dnaspp/html/usercontrols.asp[/url]

    Happy Programming!

    --

    Scott Mitchell
    [email]mitchell@4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]
    [url]http://www.ASPFAQs.com[/url]
    [url]http://www.ASPMessageboard.com[/url]

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP] Guest

  4. #3

    Default Re: User Control - setting properties

    Works great, thanks

    "Scott Mitchell [MVP]" <mitchell@4guysfromrolla.com> wrote in message
    news:4096B0C3.3050306@4guysfromrolla.com...
    > > User control has a label in a html table and I want to set the text
    property
    > > of the label from code behind. (MyLabel)
    > >
    > > <%@ Register TagPrefix="MCP" TagName="TOPMENU" src="TopMenu.ascx" %>
    > > <HTML>
    > >
    > >
    > > FORM....
    > > <MCP:TOPMENU id="TopMenu1" runat="server"></MCP:TOPMENU>
    > >
    > >
    > > CODE BEHIND...PAGE LOAD
    > >
    > > ??? MyLabel.Text="Something"
    > >
    > > Can't see the label object in the code behind... Why not? How do I get
    to
    > > it?
    >
    > John, give the User Control a public string property, like MyLabelText.
    > Then in the Page_Load event of the User Control, set its Label's Text
    > property to the value of the MyLabelText property. In the ASP.NET Web
    > page's code behind class, set the User Control's MyLabelText like so:
    >
    > TopMenu1.MyLabelText = "Foo"
    >
    > (You'll need to have manually added in a reference to TopMenu1 in your
    > class, like:
    >
    > Protected TopMenu1 as TopMenu
    > )
    >
    > For more information, be sure to read:
    >
    > An Extensive Examination Of User Controls
    >
    [url]http://msdn.microsoft.com/asp.net/using/building/webcontrols/default.aspx?pu[/url]
    ll=/library/en-us/dnaspp/html/usercontrols.asp
    >
    > Happy Programming!
    >
    > --
    >
    > Scott Mitchell
    > [email]mitchell@4guysfromrolla.com[/email]
    > [url]http://www.4GuysFromRolla.com[/url]
    > [url]http://www.ASPFAQs.com[/url]
    > [url]http://www.ASPMessageboard.com[/url]
    >
    > * When you think ASP, think 4GuysFromRolla.com!

    John Carnahan Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139