className Attribute (UserControls)

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

  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. Similar Questions and Discussions

    1. Retrive data from attribute spaced attribute.
      Hi. I'm retrieving data from an excel sheet. But one of the attributes is name "Phone private". This is a problem when I want to write out the...
    2. #24729 [Ver->Csd]: $obj = new $className; causes crash when $className is not set
      ID: 24729 Updated by: helly@php.net Reported By: proton at fangen dot net -Status: Verified +Status: ...
    3. #24729 [Opn->Ver]: $obj = new $className; causes crash when $className is not set
      ID: 24729 Updated by: derick@php.net Reported By: proton at fangen dot net -Status: Open +Status: ...
    4. #24729 [NEW]: $obj = new $className; causes crash when $className is not set
      From: proton at fangen dot net Operating system: Windows XP Home PHP version: 5CVS-2003-07-20 (dev) PHP Bug Type: ...
    5. global.asax classname
      i have the following in global.asax: <%@ Application Codebehind="Global.asax.cs" Inherits="Foo.Global" Classname="AppClass" %> but wherever i...
  3. #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

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