Professional Web Applications Themes

Problem with Property values in HTML tag - ASP.NET Building Controls

When I set one of my custom control properties programmtically the control, as below, the control gets the value and spits it back out at the right place. Everything works fine. EdsControl.TrailDelimiter = " ***> "; When I set the property value in the tag the property value is not set in the control. <spcg:EdsControl TrailDelimiter=" ***> " runat="server"> I've not setup the designer stuff yet to automatically show the available control properties in HTML-mode. Ed...

  1. #1

    Default Problem with Property values in HTML tag


    When I set one of my custom control properties programmtically
    the control, as below, the control gets the value and spits
    it back out at the right place. Everything works fine.

    EdsControl.TrailDelimiter = " ***> ";


    When I set the property value in the tag the property value
    is not set in the control.

    <spcg:EdsControl TrailDelimiter=" ***> " runat="server">


    I've not setup the designer stuff yet to automatically show the
    available control properties in HTML-mode.

    Ed

    Ed Swartz Guest

  2. #2

    Default Re: Problem with Property values in HTML tag

    I figured out my problem. Since I spent an hour or two (or was it
    three?) figuring this out I thought others might benefit
    from my efforts:

    Here's the snippets of my code:

    * I created some HTML to declaratively set a property value:

    <spcg:MyControl TrailDelimiter=" ***>" runat="server"></spcg:MyControl>


    * I created a property in my control:

    public string TrailDelimiter
    {
    get { return (string)ViewState[ "TrailDelimiter" ]; }

    set
    {
    ViewState[ "TrailDelimiter" ] = value;
    }
    }


    * I wired up events in my constructor:

    this.Init += new System.EventHandler( Page_Init );
    this.Load += new System.EventHandler( Page_Load );



    * In my Page_Init I initialized properties:

    TrailDelimiter = " > ";


    Here's what happended:

    1) My control was instantiated.

    2) The property values from the HTML declarative syntax
    were used to set the property values.

    Now: TrailDelimier = " ***>"

    3) My Page_Init was called which set TrailDelimiter
    to " > " over-riding the value from the page HTML.

    4) Then when I went to use TrailDelimiter I expected it to be
    set to " ***>" but it was the value set in Page_Init.


    So, the solution is to remove setting of the property value
    in the Page_Init and to set the default value of the
    property in the property method:

    public string TrailDelimiter
    {
    get
    {
    if( (object)ViewState[ "TrailDelimier" ] == null ) return " > ";
    return (string)ViewState[ "TrailDelimiter" ];
    }

    set
    {
    ViewState[ "TrailDelimiter" ] = value;
    }
    }

    Ps. If anyone makes flowcharts of the control life-cycle
    remember to include setting of property values from the
    HTML declarative page syntax.

    I hope this helps others.

    Ed


    Ed Swartz wrote:
    >
    > When I set one of my custom control properties programmtically
    > the control, as below, the control gets the value and spits
    > it back out at the right place. Everything works fine.
    >
    > EdsControl.TrailDelimiter = " ***> ";
    >
    >
    > When I set the property value in the tag the property value
    > is not set in the control.
    >
    > <spcg:EdsControl TrailDelimiter=" ***> " runat="server">
    >
    >
    > I've not setup the designer stuff yet to automatically show the
    > available control properties in HTML-mode.
    >
    > Ed
    >
    Ed Swartz Guest

Similar Threads

  1. Resetting Property Values
    By Scott G. in forum ASP.NET Building Controls
    Replies: 2
    Last Post: July 13th, 01:36 PM
  2. Property with multiple values
    By Henrik Grotle in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 16th, 08:25 AM
  3. provide several values for a String property
    By Oleg Ogurok in forum ASP.NET Building Controls
    Replies: 1
    Last Post: September 10th, 01:30 AM
  4. Custom Property doesn't save values
    By Evgeni Presmann in forum ASP.NET Building Controls
    Replies: 3
    Last Post: July 28th, 11:40 AM
  5. Sorting property list by the values
    By Arctic Flea webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 2
    Last Post: July 18th, 01:14 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