Professional Web Applications Themes

className Attribute (UserControls) - ASP.NET General

Hello, I am reading a book on ASP.NET Applications and don't understand what the writer is trying to say. It is stated that (when converting a Web Page to a User Control) that: "Adding a className attribute to the Control directive allows you to specify the class name for the user control and it allows strong typing of the control when it's added to the page or other server controls programmatically." Does this mean that using a className attribute will allow me to use the code-behind page to add the control to my ASP.NET page? I have tried this and ...

  1. #1

    Default className Attribute (UserControls)

    Hello, I am reading a book on ASP.NET Applications and don't understand what
    the writer is trying to say. It is stated that (when converting a Web Page
    to a User Control) that:

    "Adding a className attribute to the Control directive allows you to
    specify the class name for the user control and it allows strong typing of
    the control when it's added to the page or other server controls
    programmatically."

    Does this mean that using a className attribute will allow me to use the
    code-behind page to add the control to my ASP.NET page? I have tried this
    and if this is what it means them I am going something wrong. If I am
    missunderstanding what the author is saying can you please give me a code
    example (either way) of what is being said.

    Thanks

    Chuck


    Charles A. Lackman Guest

  2. #2

    Thumbs up Re: className Attribute (UserControls)

    yes that is true, by adding a classname attribute to the user controls ascx file you should be able to load the control from code behind. So:

    <% Control Language="C#" AutoEventWireup="true" CodeFile="CustomBasketsSummary.ascx.cs"
    ClassName="CustomBaskets.CustomBasketsSummaryContr ol" Inherits="CustomBaskets.CustomBasketsSummary" %>

    by having the above in the user control you can then load this control in a different page or control using its strongly typed name:

    Controls.Add(LoadControl(typeof(CustomBaskets.Cust omBasketsSummaryControl), null));
    Unregistered Guest

Similar Threads

  1. Retrive data from attribute spaced attribute.
    By kruse in forum Coldfusion Database Access
    Replies: 3
    Last Post: January 4th, 12:27 PM
  2. Replies: 0
    Last Post: July 20th, 08:46 PM
  3. Replies: 0
    Last Post: July 20th, 08:21 PM
  4. #24729 [NEW]: $obj = new $className; causes crash when $className is not set
    By proton at fangen dot net in forum PHP Development
    Replies: 0
    Last Post: July 20th, 07:58 PM
  5. global.asax classname
    By noname in forum ASP.NET General
    Replies: 1
    Last Post: July 16th, 07:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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