Custom Server Control Can't read design time property

Discussion in 'ASP .Net' started by Shimon Sim, Jul 29, 2005.

  1. Shimon Sim

    Shimon Sim Guest

    I have a custom composite control
    I have following property

    [Browsable(true)]

    [Category("Appearance")]

    [Editor(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]

    [DefaultValue("")]

    public string MiddleImageUrl

    {

    get

    {

    if(ViewState["MiddleImageUrl"]!=null)

    return ViewState["MiddleImageUrl"].ToString();

    else

    return null

    }

    set

    {

    ViewState["MiddleImageUrl"]=value;

    }

    }

    For some reason if I set up it up during design time it always "".

    I can't get why and what should I do to make it work.

    Thanks you

    Shimon.
    Shimon Sim, Jul 29, 2005
    #1
    1. Advertising

  2. Hi Shimon,

    Welcome to ASPNET newsgroup.
    As for the Property of ASP.NET custom webserver control, they're processed
    differently between runtime and design-time. For those which store/persist
    the property in Viewstate, this only behave so at runtime where there is
    ViewState collection exists in memory. For design-time, the VS.NET IDE
    won't use the ViewState since there's no ASP.NET runtime exists. In
    design-time, all the value we set for the property in IDE will be persisted
    in the page template (aspx) according to our control's declaration. The
    "System.Web.UI.PersistenceModeAttribute" attribute is just to help define
    how to persist the control's property value at design-time, for example:

    [PersistenceMode(PersistenceMode.Attribute),
    public string Text
    {
    get ... set....
    }

    indicate the "Text" property's value will be persisted as an attribute in
    the Control's tag at design-time. This will result in the below conent in
    aspx page when we using the control:

    <prefix:ControlName id=xxxx Text="xxxx' ...../>

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)








    --------------------
    | From: "Shimon Sim" <>
    | Subject: Custom Server Control Can't read design time property
    | Date: Thu, 28 Jul 2005 21:25:13 -0400
    | Lines: 48
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | X-RFC2646: Format=Flowed; Original
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:115073
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | I have a custom composite control
    | I have following property
    |
    | [Browsable(true)]
    |
    | [Category("Appearance")]
    |
    | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    typeof(UITypeEditor))]
    |
    | [DefaultValue("")]
    |
    | public string MiddleImageUrl
    |
    | {
    |
    | get
    |
    | {
    |
    | if(ViewState["MiddleImageUrl"]!=null)
    |
    | return ViewState["MiddleImageUrl"].ToString();
    |
    | else
    |
    | return null
    |
    | }
    |
    | set
    |
    | {
    |
    | ViewState["MiddleImageUrl"]=value;
    |
    | }
    |
    | }
    |
    | For some reason if I set up it up during design time it always "".
    |
    | I can't get why and what should I do to make it work.
    |
    | Thanks you
    |
    | Shimon.
    |
    |
    |
    Steven Cheng[MSFT], Jul 29, 2005
    #2
    1. Advertising

  3. Shimon Sim

    Shimon Sim Guest

    Thanks Steven.
    I tried to use variable but it didn't work. I was thinking that could be the
    problem is that I am trying to use it in CreateChildControls() method and
    then it not available. Can you confirm my guess.
    Thank you
    Shimon.

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Shimon,
    >
    > Welcome to ASPNET newsgroup.
    > As for the Property of ASP.NET custom webserver control, they're processed
    > differently between runtime and design-time. For those which store/persist
    > the property in Viewstate, this only behave so at runtime where there is
    > ViewState collection exists in memory. For design-time, the VS.NET IDE
    > won't use the ViewState since there's no ASP.NET runtime exists. In
    > design-time, all the value we set for the property in IDE will be
    > persisted
    > in the page template (aspx) according to our control's declaration. The
    > "System.Web.UI.PersistenceModeAttribute" attribute is just to help define
    > how to persist the control's property value at design-time, for example:
    >
    > [PersistenceMode(PersistenceMode.Attribute),
    > public string Text
    > {
    > get ... set....
    > }
    >
    > indicate the "Text" property's value will be persisted as an attribute in
    > the Control's tag at design-time. This will result in the below conent in
    > aspx page when we using the control:
    >
    > <prefix:ControlName id=xxxx Text="xxxx' ...../>
    >
    > Hope helps. Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    >
    >
    >
    >
    >
    > --------------------
    > | From: "Shimon Sim" <>
    > | Subject: Custom Server Control Can't read design time property
    > | Date: Thu, 28 Jul 2005 21:25:13 -0400
    > | Lines: 48
    > | X-Priority: 3
    > | X-MSMail-Priority: Normal
    > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    > | X-RFC2646: Format=Flowed; Original
    > | Message-ID: <>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet:115073
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > |
    > | I have a custom composite control
    > | I have following property
    > |
    > | [Browsable(true)]
    > |
    > | [Category("Appearance")]
    > |
    > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    > typeof(UITypeEditor))]
    > |
    > | [DefaultValue("")]
    > |
    > | public string MiddleImageUrl
    > |
    > | {
    > |
    > | get
    > |
    > | {
    > |
    > | if(ViewState["MiddleImageUrl"]!=null)
    > |
    > | return ViewState["MiddleImageUrl"].ToString();
    > |
    > | else
    > |
    > | return null
    > |
    > | }
    > |
    > | set
    > |
    > | {
    > |
    > | ViewState["MiddleImageUrl"]=value;
    > |
    > | }
    > |
    > | }
    > |
    > | For some reason if I set up it up during design time it always "".
    > |
    > | I can't get why and what should I do to make it work.
    > |
    > | Thanks you
    > |
    > | Shimon.
    > |
    > |
    > |
    >
    Shimon Sim, Jul 29, 2005
    #3
  4. Hi Shimon,

    Thanks for your response. As you said that
    " the problem is that I am trying to use it in CreateChildControls() method
    and then it not available"

    then, it still should be a runtime problem(not design-time). For ASP.NET
    Server Control, it'll pass through a certain sequence of events when being
    loaded into page on the serverside. And for composite control , the
    CreateChildControl will be called at certain time by the asp.net runtime.
    Generally, the first time page is requested, since there is no viewstate
    yet, the composite control's "CreateChildControls" maybe called after
    Page_Load and before PreRender. And when in the page's PostBack requests,
    since the page/controls need to restore states from ViewState, the
    composite control's "CreateChildControls" will be called before loading
    viewstate(dynamically created control will call LoadViewState after being
    added into parent collection).

    So, generally it's quite normal that we can't access the ViewState in
    CreateChildControl. Is there any particular requirement that you need to
    access viewstate in CreateChildControls? Generally, for composite control,
    the "CreatecontrolControls" method should contains the code that only
    constructing the basic control hierarchy. For manipulate Properites which
    persisted in ViewState, it is recommended to be put in postback event (at
    that time the viewstate has been successfully loaded).

    Please feel free to let me know if you have any particular problem or
    anything else unclear.

    Thanks & Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)


    --------------------
    | From: "Shimon Sim" <>
    | References: <>
    <>
    | Subject: Re: Custom Server Control Can't read design time property
    | Date: Fri, 29 Jul 2005 08:09:13 -0400
    | Lines: 122
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | X-RFC2646: Format=Flowed; Original
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:115128
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Thanks Steven.
    | I tried to use variable but it didn't work. I was thinking that could be
    the
    | problem is that I am trying to use it in CreateChildControls() method and
    | then it not available. Can you confirm my guess.
    | Thank you
    | Shimon.
    |
    | "Steven Cheng[MSFT]" <> wrote in message
    | news:...
    | > Hi Shimon,
    | >
    | > Welcome to ASPNET newsgroup.
    | > As for the Property of ASP.NET custom webserver control, they're
    processed
    | > differently between runtime and design-time. For those which
    store/persist
    | > the property in Viewstate, this only behave so at runtime where there is
    | > ViewState collection exists in memory. For design-time, the VS.NET IDE
    | > won't use the ViewState since there's no ASP.NET runtime exists. In
    | > design-time, all the value we set for the property in IDE will be
    | > persisted
    | > in the page template (aspx) according to our control's declaration. The
    | > "System.Web.UI.PersistenceModeAttribute" attribute is just to help
    define
    | > how to persist the control's property value at design-time, for example:
    | >
    | > [PersistenceMode(PersistenceMode.Attribute),
    | > public string Text
    | > {
    | > get ... set....
    | > }
    | >
    | > indicate the "Text" property's value will be persisted as an attribute
    in
    | > the Control's tag at design-time. This will result in the below conent
    in
    | > aspx page when we using the control:
    | >
    | > <prefix:ControlName id=xxxx Text="xxxx' ...../>
    | >
    | > Hope helps. Thanks,
    | >
    | > Steven Cheng
    | > Microsoft Online Support
    | >
    | > Get Secure! www.microsoft.com/security
    | > (This posting is provided "AS IS", with no warranties, and confers no
    | > rights.)
    | >
    | >
    | >
    | >
    | >
    | >
    | >
    | >
    | > --------------------
    | > | From: "Shimon Sim" <>
    | > | Subject: Custom Server Control Can't read design time property
    | > | Date: Thu, 28 Jul 2005 21:25:13 -0400
    | > | Lines: 48
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | > | X-RFC2646: Format=Flowed; Original
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet:115073
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > |
    | > | I have a custom composite control
    | > | I have following property
    | > |
    | > | [Browsable(true)]
    | > |
    | > | [Category("Appearance")]
    | > |
    | > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    | > typeof(UITypeEditor))]
    | > |
    | > | [DefaultValue("")]
    | > |
    | > | public string MiddleImageUrl
    | > |
    | > | {
    | > |
    | > | get
    | > |
    | > | {
    | > |
    | > | if(ViewState["MiddleImageUrl"]!=null)
    | > |
    | > | return ViewState["MiddleImageUrl"].ToString();
    | > |
    | > | else
    | > |
    | > | return null
    | > |
    | > | }
    | > |
    | > | set
    | > |
    | > | {
    | > |
    | > | ViewState["MiddleImageUrl"]=value;
    | > |
    | > | }
    | > |
    | > | }
    | > |
    | > | For some reason if I set up it up during design time it always "".
    | > |
    | > | I can't get why and what should I do to make it work.
    | > |
    | > | Thanks you
    | > |
    | > | Shimon.
    | > |
    | > |
    | > |
    | >
    |
    |
    |
    Steven Cheng[MSFT], Aug 1, 2005
    #4
  5. Shimon Sim

    Shimon Sim Guest

    Thank you Steve on this.
    Here is the code
    Currently I implemented the property like this
    [Browsable(true)]

    [Category("Appearance")]

    [Editor(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(UITypeEditor))]

    [DefaultValue("")]

    public string MiddleImageUrl

    {

    get

    {

    if(ViewState["MiddleImageUrl"]!=null)

    return ViewState["MiddleImageUrl"].ToString();

    else

    return middleImageUrl;

    }

    set

    {

    ViewState["MiddleImageUrl"]=value;

    middleImageUrl=value;

    }

    }



    The method that uses it is like this.

    protected override void CreateChildControls()

    {


    Controls.Add(new LiteralControl("<table border =\"0\"
    cellspacing=\"0\"><tr><td>"));

    Controls.Add(leftImage);


    Controls.Add(new LiteralControl("</td><td width=\"100%\"
    background=\""+MiddleImageUrl+"\">"));

    lblTitle.Width=Unit.Parse("100%");

    Controls.Add(lblTitle);

    Controls.Add(new LiteralControl("</td><td>"));

    Controls.Add(rightImage);



    Controls.Add(new LiteralControl("</td></tr>"));

    Controls.Add(new LiteralControl("<tr><td colspan=3>"));

    pnlBody.Width=Unit.Parse("100%");

    double height=this.Height.Value-lblTitle.Height.Value;

    pnlBody.Height=Unit.Parse(height.ToString());

    Controls.Add(pnlBody);

    Controls.Add(new LiteralControl("</td></td></table>"));

    }

    What I get is: I set up this property via VS.NET during design time

    at design time I see the image but at run time I don't have any image at
    all - the field in html is blank.

    Thank you very much for help.

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Shimon,
    >
    > Thanks for your response. As you said that
    > " the problem is that I am trying to use it in CreateChildControls()
    > method
    > and then it not available"
    >
    > then, it still should be a runtime problem(not design-time). For ASP.NET
    > Server Control, it'll pass through a certain sequence of events when being
    > loaded into page on the serverside. And for composite control , the
    > CreateChildControl will be called at certain time by the asp.net runtime.
    > Generally, the first time page is requested, since there is no viewstate
    > yet, the composite control's "CreateChildControls" maybe called after
    > Page_Load and before PreRender. And when in the page's PostBack requests,
    > since the page/controls need to restore states from ViewState, the
    > composite control's "CreateChildControls" will be called before loading
    > viewstate(dynamically created control will call LoadViewState after being
    > added into parent collection).
    >
    > So, generally it's quite normal that we can't access the ViewState in
    > CreateChildControl. Is there any particular requirement that you need to
    > access viewstate in CreateChildControls? Generally, for composite
    > control,
    > the "CreatecontrolControls" method should contains the code that only
    > constructing the basic control hierarchy. For manipulate Properites which
    > persisted in ViewState, it is recommended to be put in postback event (at
    > that time the viewstate has been successfully loaded).
    >
    > Please feel free to let me know if you have any particular problem or
    > anything else unclear.
    >
    > Thanks & Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    > --------------------
    > | From: "Shimon Sim" <>
    > | References: <>
    > <>
    > | Subject: Re: Custom Server Control Can't read design time property
    > | Date: Fri, 29 Jul 2005 08:09:13 -0400
    > | Lines: 122
    > | X-Priority: 3
    > | X-MSMail-Priority: Normal
    > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    > | X-RFC2646: Format=Flowed; Original
    > | Message-ID: <>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet:115128
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > |
    > | Thanks Steven.
    > | I tried to use variable but it didn't work. I was thinking that could be
    > the
    > | problem is that I am trying to use it in CreateChildControls() method
    > and
    > | then it not available. Can you confirm my guess.
    > | Thank you
    > | Shimon.
    > |
    > | "Steven Cheng[MSFT]" <> wrote in message
    > | news:...
    > | > Hi Shimon,
    > | >
    > | > Welcome to ASPNET newsgroup.
    > | > As for the Property of ASP.NET custom webserver control, they're
    > processed
    > | > differently between runtime and design-time. For those which
    > store/persist
    > | > the property in Viewstate, this only behave so at runtime where there
    > is
    > | > ViewState collection exists in memory. For design-time, the VS.NET IDE
    > | > won't use the ViewState since there's no ASP.NET runtime exists. In
    > | > design-time, all the value we set for the property in IDE will be
    > | > persisted
    > | > in the page template (aspx) according to our control's declaration.
    > The
    > | > "System.Web.UI.PersistenceModeAttribute" attribute is just to help
    > define
    > | > how to persist the control's property value at design-time, for
    > example:
    > | >
    > | > [PersistenceMode(PersistenceMode.Attribute),
    > | > public string Text
    > | > {
    > | > get ... set....
    > | > }
    > | >
    > | > indicate the "Text" property's value will be persisted as an attribute
    > in
    > | > the Control's tag at design-time. This will result in the below conent
    > in
    > | > aspx page when we using the control:
    > | >
    > | > <prefix:ControlName id=xxxx Text="xxxx' ...../>
    > | >
    > | > Hope helps. Thanks,
    > | >
    > | > Steven Cheng
    > | > Microsoft Online Support
    > | >
    > | > Get Secure! www.microsoft.com/security
    > | > (This posting is provided "AS IS", with no warranties, and confers no
    > | > rights.)
    > | >
    > | >
    > | >
    > | >
    > | >
    > | >
    > | >
    > | >
    > | > --------------------
    > | > | From: "Shimon Sim" <>
    > | > | Subject: Custom Server Control Can't read design time property
    > | > | Date: Thu, 28 Jul 2005 21:25:13 -0400
    > | > | Lines: 48
    > | > | X-Priority: 3
    > | > | X-MSMail-Priority: Normal
    > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    > | > | X-RFC2646: Format=Flowed; Original
    > | > | Message-ID: <>
    > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | > | Path:
    > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    > | > | Xref: TK2MSFTNGXA01.phx.gbl
    > | > microsoft.public.dotnet.framework.aspnet:115073
    > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > | > |
    > | > | I have a custom composite control
    > | > | I have following property
    > | > |
    > | > | [Browsable(true)]
    > | > |
    > | > | [Category("Appearance")]
    > | > |
    > | > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    > | > typeof(UITypeEditor))]
    > | > |
    > | > | [DefaultValue("")]
    > | > |
    > | > | public string MiddleImageUrl
    > | > |
    > | > | {
    > | > |
    > | > | get
    > | > |
    > | > | {
    > | > |
    > | > | if(ViewState["MiddleImageUrl"]!=null)
    > | > |
    > | > | return ViewState["MiddleImageUrl"].ToString();
    > | > |
    > | > | else
    > | > |
    > | > | return null
    > | > |
    > | > | }
    > | > |
    > | > | set
    > | > |
    > | > | {
    > | > |
    > | > | ViewState["MiddleImageUrl"]=value;
    > | > |
    > | > | }
    > | > |
    > | > | }
    > | > |
    > | > | For some reason if I set up it up during design time it always "".
    > | > |
    > | > | I can't get why and what should I do to make it work.
    > | > |
    > | > | Thanks you
    > | > |
    > | > | Shimon.
    > | > |
    > | > |
    > | > |
    > | >
    > |
    > |
    > |
    >
    Shimon Sim, Aug 1, 2005
    #5
  6. Thanks for your further followup Shimon,

    From the code you provided , you retrieve the url info from ViewState in
    CreateChildControl method, as I've mentioend in the last reply, since the
    CreateChildControl will generally be called before the control's Loading
    ViewState, so at that time the ViewState of the control is still
    unavailable. For such scenario, the most common means is Retrieve the
    viewstate info in some later events such as postback events or Prerender
    events (at that time ViewState has been successfully loaded) and we can
    adjust the our sub controls' properteis through Viewstate at that time.

    In addition, from your control's "CreateChildControls" method code, it's
    much more like a Render control rather than a composite control. For such
    control, I'll recommend that you change it to Render control, just put the
    control's output constructing task in the "Render" method (the viewstate is
    surely available in it).

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)



    --------------------
    | From: "Shimon Sim" <>
    | References: <>
    <>
    <>
    <>
    | Subject: Re: Custom Server Control Can't read design time property
    | Date: Mon, 1 Aug 2005 08:21:28 -0400
    | Lines: 292
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:115431
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Thank you Steve on this.
    | Here is the code
    | Currently I implemented the property like this
    | [Browsable(true)]
    |
    | [Category("Appearance")]
    |
    | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    typeof(UITypeEditor))]
    |
    | [DefaultValue("")]
    |
    | public string MiddleImageUrl
    |
    | {
    |
    | get
    |
    | {
    |
    | if(ViewState["MiddleImageUrl"]!=null)
    |
    | return ViewState["MiddleImageUrl"].ToString();
    |
    | else
    |
    | return middleImageUrl;
    |
    | }
    |
    | set
    |
    | {
    |
    | ViewState["MiddleImageUrl"]=value;
    |
    | middleImageUrl=value;
    |
    | }
    |
    | }
    |
    |
    |
    | The method that uses it is like this.
    |
    | protected override void CreateChildControls()
    |
    | {
    |
    |
    | Controls.Add(new LiteralControl("<table border =\"0\"
    | cellspacing=\"0\"><tr><td>"));
    |
    | Controls.Add(leftImage);
    |
    |
    | Controls.Add(new LiteralControl("</td><td width=\"100%\"
    | background=\""+MiddleImageUrl+"\">"));
    |
    | lblTitle.Width=Unit.Parse("100%");
    |
    | Controls.Add(lblTitle);
    |
    | Controls.Add(new LiteralControl("</td><td>"));
    |
    | Controls.Add(rightImage);
    |
    |
    |
    | Controls.Add(new LiteralControl("</td></tr>"));
    |
    | Controls.Add(new LiteralControl("<tr><td colspan=3>"));
    |
    | pnlBody.Width=Unit.Parse("100%");
    |
    | double height=this.Height.Value-lblTitle.Height.Value;
    |
    | pnlBody.Height=Unit.Parse(height.ToString());
    |
    | Controls.Add(pnlBody);
    |
    | Controls.Add(new LiteralControl("</td></td></table>"));
    |
    | }
    |
    | What I get is: I set up this property via VS.NET during design time
    |
    | at design time I see the image but at run time I don't have any image at
    | all - the field in html is blank.
    |
    | Thank you very much for help.
    |
    | "Steven Cheng[MSFT]" <> wrote in message
    | news:...
    | > Hi Shimon,
    | >
    | > Thanks for your response. As you said that
    | > " the problem is that I am trying to use it in CreateChildControls()
    | > method
    | > and then it not available"
    | >
    | > then, it still should be a runtime problem(not design-time). For ASP.NET
    | > Server Control, it'll pass through a certain sequence of events when
    being
    | > loaded into page on the serverside. And for composite control , the
    | > CreateChildControl will be called at certain time by the asp.net
    runtime.
    | > Generally, the first time page is requested, since there is no viewstate
    | > yet, the composite control's "CreateChildControls" maybe called after
    | > Page_Load and before PreRender. And when in the page's PostBack
    requests,
    | > since the page/controls need to restore states from ViewState, the
    | > composite control's "CreateChildControls" will be called before loading
    | > viewstate(dynamically created control will call LoadViewState after
    being
    | > added into parent collection).
    | >
    | > So, generally it's quite normal that we can't access the ViewState in
    | > CreateChildControl. Is there any particular requirement that you need to
    | > access viewstate in CreateChildControls? Generally, for composite
    | > control,
    | > the "CreatecontrolControls" method should contains the code that only
    | > constructing the basic control hierarchy. For manipulate Properites
    which
    | > persisted in ViewState, it is recommended to be put in postback event
    (at
    | > that time the viewstate has been successfully loaded).
    | >
    | > Please feel free to let me know if you have any particular problem or
    | > anything else unclear.
    | >
    | > Thanks & Regards,
    | >
    | > Steven Cheng
    | > Microsoft Online Support
    | >
    | > Get Secure! www.microsoft.com/security
    | > (This posting is provided "AS IS", with no warranties, and confers no
    | > rights.)
    | >
    | >
    | > --------------------
    | > | From: "Shimon Sim" <>
    | > | References: <>
    | > <>
    | > | Subject: Re: Custom Server Control Can't read design time property
    | > | Date: Fri, 29 Jul 2005 08:09:13 -0400
    | > | Lines: 122
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | > | X-RFC2646: Format=Flowed; Original
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet:115128
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > |
    | > | Thanks Steven.
    | > | I tried to use variable but it didn't work. I was thinking that could
    be
    | > the
    | > | problem is that I am trying to use it in CreateChildControls() method
    | > and
    | > | then it not available. Can you confirm my guess.
    | > | Thank you
    | > | Shimon.
    | > |
    | > | "Steven Cheng[MSFT]" <> wrote in message
    | > | news:...
    | > | > Hi Shimon,
    | > | >
    | > | > Welcome to ASPNET newsgroup.
    | > | > As for the Property of ASP.NET custom webserver control, they're
    | > processed
    | > | > differently between runtime and design-time. For those which
    | > store/persist
    | > | > the property in Viewstate, this only behave so at runtime where
    there
    | > is
    | > | > ViewState collection exists in memory. For design-time, the VS.NET
    IDE
    | > | > won't use the ViewState since there's no ASP.NET runtime exists. In
    | > | > design-time, all the value we set for the property in IDE will be
    | > | > persisted
    | > | > in the page template (aspx) according to our control's declaration.
    | > The
    | > | > "System.Web.UI.PersistenceModeAttribute" attribute is just to help
    | > define
    | > | > how to persist the control's property value at design-time, for
    | > example:
    | > | >
    | > | > [PersistenceMode(PersistenceMode.Attribute),
    | > | > public string Text
    | > | > {
    | > | > get ... set....
    | > | > }
    | > | >
    | > | > indicate the "Text" property's value will be persisted as an
    attribute
    | > in
    | > | > the Control's tag at design-time. This will result in the below
    conent
    | > in
    | > | > aspx page when we using the control:
    | > | >
    | > | > <prefix:ControlName id=xxxx Text="xxxx' ...../>
    | > | >
    | > | > Hope helps. Thanks,
    | > | >
    | > | > Steven Cheng
    | > | > Microsoft Online Support
    | > | >
    | > | > Get Secure! www.microsoft.com/security
    | > | > (This posting is provided "AS IS", with no warranties, and confers
    no
    | > | > rights.)
    | > | >
    | > | >
    | > | >
    | > | >
    | > | >
    | > | >
    | > | >
    | > | >
    | > | > --------------------
    | > | > | From: "Shimon Sim" <>
    | > | > | Subject: Custom Server Control Can't read design time property
    | > | > | Date: Thu, 28 Jul 2005 21:25:13 -0400
    | > | > | Lines: 48
    | > | > | X-Priority: 3
    | > | > | X-MSMail-Priority: Normal
    | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | > | > | X-RFC2646: Format=Flowed; Original
    | > | > | Message-ID: <>
    | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | > | Path:
    | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | > | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet:115073
    | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > | > |
    | > | > | I have a custom composite control
    | > | > | I have following property
    | > | > |
    | > | > | [Browsable(true)]
    | > | > |
    | > | > | [Category("Appearance")]
    | > | > |
    | > | > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    | > | > typeof(UITypeEditor))]
    | > | > |
    | > | > | [DefaultValue("")]
    | > | > |
    | > | > | public string MiddleImageUrl
    | > | > |
    | > | > | {
    | > | > |
    | > | > | get
    | > | > |
    | > | > | {
    | > | > |
    | > | > | if(ViewState["MiddleImageUrl"]!=null)
    | > | > |
    | > | > | return ViewState["MiddleImageUrl"].ToString();
    | > | > |
    | > | > | else
    | > | > |
    | > | > | return null
    | > | > |
    | > | > | }
    | > | > |
    | > | > | set
    | > | > |
    | > | > | {
    | > | > |
    | > | > | ViewState["MiddleImageUrl"]=value;
    | > | > |
    | > | > | }
    | > | > |
    | > | > | }
    | > | > |
    | > | > | For some reason if I set up it up during design time it always "".
    | > | > |
    | > | > | I can't get why and what should I do to make it work.
    | > | > |
    | > | > | Thanks you
    | > | > |
    | > | > | Shimon.
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
    Steven Cheng[MSFT], Aug 2, 2005
    #6
  7. Shimon Sim

    Shimon Sim Guest

    Thank you Steven
    Shimon.
    "Steven Cheng[MSFT]" <> wrote in message
    news:8c$...
    > Thanks for your further followup Shimon,
    >
    > From the code you provided , you retrieve the url info from ViewState in
    > CreateChildControl method, as I've mentioend in the last reply, since the
    > CreateChildControl will generally be called before the control's Loading
    > ViewState, so at that time the ViewState of the control is still
    > unavailable. For such scenario, the most common means is Retrieve the
    > viewstate info in some later events such as postback events or Prerender
    > events (at that time ViewState has been successfully loaded) and we can
    > adjust the our sub controls' properteis through Viewstate at that time.
    >
    > In addition, from your control's "CreateChildControls" method code, it's
    > much more like a Render control rather than a composite control. For such
    > control, I'll recommend that you change it to Render control, just put the
    > control's output constructing task in the "Render" method (the viewstate
    > is
    > surely available in it).
    >
    > Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    > --------------------
    > | From: "Shimon Sim" <>
    > | References: <>
    > <>
    > <>
    > <>
    > | Subject: Re: Custom Server Control Can't read design time property
    > | Date: Mon, 1 Aug 2005 08:21:28 -0400
    > | Lines: 292
    > | X-Priority: 3
    > | X-MSMail-Priority: Normal
    > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    > | X-RFC2646: Format=Flowed; Original
    > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    > | Message-ID: <>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    > | Xref: TK2MSFTNGXA01.phx.gbl
    > microsoft.public.dotnet.framework.aspnet:115431
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > |
    > | Thank you Steve on this.
    > | Here is the code
    > | Currently I implemented the property like this
    > | [Browsable(true)]
    > |
    > | [Category("Appearance")]
    > |
    > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    > typeof(UITypeEditor))]
    > |
    > | [DefaultValue("")]
    > |
    > | public string MiddleImageUrl
    > |
    > | {
    > |
    > | get
    > |
    > | {
    > |
    > | if(ViewState["MiddleImageUrl"]!=null)
    > |
    > | return ViewState["MiddleImageUrl"].ToString();
    > |
    > | else
    > |
    > | return middleImageUrl;
    > |
    > | }
    > |
    > | set
    > |
    > | {
    > |
    > | ViewState["MiddleImageUrl"]=value;
    > |
    > | middleImageUrl=value;
    > |
    > | }
    > |
    > | }
    > |
    > |
    > |
    > | The method that uses it is like this.
    > |
    > | protected override void CreateChildControls()
    > |
    > | {
    > |
    > |
    > | Controls.Add(new LiteralControl("<table border =\"0\"
    > | cellspacing=\"0\"><tr><td>"));
    > |
    > | Controls.Add(leftImage);
    > |
    > |
    > | Controls.Add(new LiteralControl("</td><td width=\"100%\"
    > | background=\""+MiddleImageUrl+"\">"));
    > |
    > | lblTitle.Width=Unit.Parse("100%");
    > |
    > | Controls.Add(lblTitle);
    > |
    > | Controls.Add(new LiteralControl("</td><td>"));
    > |
    > | Controls.Add(rightImage);
    > |
    > |
    > |
    > | Controls.Add(new LiteralControl("</td></tr>"));
    > |
    > | Controls.Add(new LiteralControl("<tr><td colspan=3>"));
    > |
    > | pnlBody.Width=Unit.Parse("100%");
    > |
    > | double height=this.Height.Value-lblTitle.Height.Value;
    > |
    > | pnlBody.Height=Unit.Parse(height.ToString());
    > |
    > | Controls.Add(pnlBody);
    > |
    > | Controls.Add(new LiteralControl("</td></td></table>"));
    > |
    > | }
    > |
    > | What I get is: I set up this property via VS.NET during design time
    > |
    > | at design time I see the image but at run time I don't have any image at
    > | all - the field in html is blank.
    > |
    > | Thank you very much for help.
    > |
    > | "Steven Cheng[MSFT]" <> wrote in message
    > | news:...
    > | > Hi Shimon,
    > | >
    > | > Thanks for your response. As you said that
    > | > " the problem is that I am trying to use it in CreateChildControls()
    > | > method
    > | > and then it not available"
    > | >
    > | > then, it still should be a runtime problem(not design-time). For
    > ASP.NET
    > | > Server Control, it'll pass through a certain sequence of events when
    > being
    > | > loaded into page on the serverside. And for composite control , the
    > | > CreateChildControl will be called at certain time by the asp.net
    > runtime.
    > | > Generally, the first time page is requested, since there is no
    > viewstate
    > | > yet, the composite control's "CreateChildControls" maybe called after
    > | > Page_Load and before PreRender. And when in the page's PostBack
    > requests,
    > | > since the page/controls need to restore states from ViewState, the
    > | > composite control's "CreateChildControls" will be called before
    > loading
    > | > viewstate(dynamically created control will call LoadViewState after
    > being
    > | > added into parent collection).
    > | >
    > | > So, generally it's quite normal that we can't access the ViewState in
    > | > CreateChildControl. Is there any particular requirement that you need
    > to
    > | > access viewstate in CreateChildControls? Generally, for composite
    > | > control,
    > | > the "CreatecontrolControls" method should contains the code that only
    > | > constructing the basic control hierarchy. For manipulate Properites
    > which
    > | > persisted in ViewState, it is recommended to be put in postback event
    > (at
    > | > that time the viewstate has been successfully loaded).
    > | >
    > | > Please feel free to let me know if you have any particular problem or
    > | > anything else unclear.
    > | >
    > | > Thanks & Regards,
    > | >
    > | > Steven Cheng
    > | > Microsoft Online Support
    > | >
    > | > Get Secure! www.microsoft.com/security
    > | > (This posting is provided "AS IS", with no warranties, and confers no
    > | > rights.)
    > | >
    > | >
    > | > --------------------
    > | > | From: "Shimon Sim" <>
    > | > | References: <>
    > | > <>
    > | > | Subject: Re: Custom Server Control Can't read design time property
    > | > | Date: Fri, 29 Jul 2005 08:09:13 -0400
    > | > | Lines: 122
    > | > | X-Priority: 3
    > | > | X-MSMail-Priority: Normal
    > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    > | > | X-RFC2646: Format=Flowed; Original
    > | > | Message-ID: <>
    > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | > | Path:
    > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    > | > | Xref: TK2MSFTNGXA01.phx.gbl
    > | > microsoft.public.dotnet.framework.aspnet:115128
    > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > | > |
    > | > | Thanks Steven.
    > | > | I tried to use variable but it didn't work. I was thinking that
    > could
    > be
    > | > the
    > | > | problem is that I am trying to use it in CreateChildControls()
    > method
    > | > and
    > | > | then it not available. Can you confirm my guess.
    > | > | Thank you
    > | > | Shimon.
    > | > |
    > | > | "Steven Cheng[MSFT]" <> wrote in message
    > | > | news:...
    > | > | > Hi Shimon,
    > | > | >
    > | > | > Welcome to ASPNET newsgroup.
    > | > | > As for the Property of ASP.NET custom webserver control, they're
    > | > processed
    > | > | > differently between runtime and design-time. For those which
    > | > store/persist
    > | > | > the property in Viewstate, this only behave so at runtime where
    > there
    > | > is
    > | > | > ViewState collection exists in memory. For design-time, the VS.NET
    > IDE
    > | > | > won't use the ViewState since there's no ASP.NET runtime exists.
    > In
    > | > | > design-time, all the value we set for the property in IDE will be
    > | > | > persisted
    > | > | > in the page template (aspx) according to our control's
    > declaration.
    > | > The
    > | > | > "System.Web.UI.PersistenceModeAttribute" attribute is just to help
    > | > define
    > | > | > how to persist the control's property value at design-time, for
    > | > example:
    > | > | >
    > | > | > [PersistenceMode(PersistenceMode.Attribute),
    > | > | > public string Text
    > | > | > {
    > | > | > get ... set....
    > | > | > }
    > | > | >
    > | > | > indicate the "Text" property's value will be persisted as an
    > attribute
    > | > in
    > | > | > the Control's tag at design-time. This will result in the below
    > conent
    > | > in
    > | > | > aspx page when we using the control:
    > | > | >
    > | > | > <prefix:ControlName id=xxxx Text="xxxx' ...../>
    > | > | >
    > | > | > Hope helps. Thanks,
    > | > | >
    > | > | > Steven Cheng
    > | > | > Microsoft Online Support
    > | > | >
    > | > | > Get Secure! www.microsoft.com/security
    > | > | > (This posting is provided "AS IS", with no warranties, and confers
    > no
    > | > | > rights.)
    > | > | >
    > | > | >
    > | > | >
    > | > | >
    > | > | >
    > | > | >
    > | > | >
    > | > | >
    > | > | > --------------------
    > | > | > | From: "Shimon Sim" <>
    > | > | > | Subject: Custom Server Control Can't read design time property
    > | > | > | Date: Thu, 28 Jul 2005 21:25:13 -0400
    > | > | > | Lines: 48
    > | > | > | X-Priority: 3
    > | > | > | X-MSMail-Priority: Normal
    > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    > | > | > | X-RFC2646: Format=Flowed; Original
    > | > | > | Message-ID: <>
    > | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    > | > | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    > | > | > | Path:
    > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    > | > | > | Xref: TK2MSFTNGXA01.phx.gbl
    > | > | > microsoft.public.dotnet.framework.aspnet:115073
    > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    > | > | > |
    > | > | > | I have a custom composite control
    > | > | > | I have following property
    > | > | > |
    > | > | > | [Browsable(true)]
    > | > | > |
    > | > | > | [Category("Appearance")]
    > | > | > |
    > | > | > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    > | > | > typeof(UITypeEditor))]
    > | > | > |
    > | > | > | [DefaultValue("")]
    > | > | > |
    > | > | > | public string MiddleImageUrl
    > | > | > |
    > | > | > | {
    > | > | > |
    > | > | > | get
    > | > | > |
    > | > | > | {
    > | > | > |
    > | > | > | if(ViewState["MiddleImageUrl"]!=null)
    > | > | > |
    > | > | > | return ViewState["MiddleImageUrl"].ToString();
    > | > | > |
    > | > | > | else
    > | > | > |
    > | > | > | return null
    > | > | > |
    > | > | > | }
    > | > | > |
    > | > | > | set
    > | > | > |
    > | > | > | {
    > | > | > |
    > | > | > | ViewState["MiddleImageUrl"]=value;
    > | > | > |
    > | > | > | }
    > | > | > |
    > | > | > | }
    > | > | > |
    > | > | > | For some reason if I set up it up during design time it always
    > "".
    > | > | > |
    > | > | > | I can't get why and what should I do to make it work.
    > | > | > |
    > | > | > | Thanks you
    > | > | > |
    > | > | > | Shimon.
    > | > | > |
    > | > | > |
    > | > | > |
    > | > | >
    > | > |
    > | > |
    > | > |
    > | >
    > |
    > |
    > |
    >
    Shimon Sim, Aug 2, 2005
    #7
  8. You're welcome Shimon,

    If there're anything else we can help later, please always feel free to
    post here.

    Thanks & Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | From: "Shimon Sim" <>
    | References: <>
    <>
    <>
    <>
    <>
    <8c$>
    | Subject: Re: Custom Server Control Can't read design time property
    | Date: Tue, 2 Aug 2005 08:23:02 -0400
    | Lines: 374
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | Message-ID: <#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.phx.gbl
    | Xref: TK2MSFTNGXA01.phx.gbl
    microsoft.public.dotnet.framework.aspnet:115613
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Thank you Steven
    | Shimon.
    | "Steven Cheng[MSFT]" <> wrote in message
    | news:8c$...
    | > Thanks for your further followup Shimon,
    | >
    | > From the code you provided , you retrieve the url info from ViewState in
    | > CreateChildControl method, as I've mentioend in the last reply, since
    the
    | > CreateChildControl will generally be called before the control's Loading
    | > ViewState, so at that time the ViewState of the control is still
    | > unavailable. For such scenario, the most common means is Retrieve the
    | > viewstate info in some later events such as postback events or
    Prerender
    | > events (at that time ViewState has been successfully loaded) and we can
    | > adjust the our sub controls' properteis through Viewstate at that time.
    | >
    | > In addition, from your control's "CreateChildControls" method code, it's
    | > much more like a Render control rather than a composite control. For
    such
    | > control, I'll recommend that you change it to Render control, just put
    the
    | > control's output constructing task in the "Render" method (the
    viewstate
    | > is
    | > surely available in it).
    | >
    | > Thanks,
    | >
    | > Steven Cheng
    | > Microsoft Online Support
    | >
    | > Get Secure! www.microsoft.com/security
    | > (This posting is provided "AS IS", with no warranties, and confers no
    | > rights.)
    | >
    | >
    | >
    | > --------------------
    | > | From: "Shimon Sim" <>
    | > | References: <>
    | > <>
    | > <>
    | > <>
    | > | Subject: Re: Custom Server Control Can't read design time property
    | > | Date: Mon, 1 Aug 2005 08:21:28 -0400
    | > | Lines: 292
    | > | X-Priority: 3
    | > | X-MSMail-Priority: Normal
    | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | > | X-RFC2646: Format=Flowed; Original
    | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | > | Message-ID: <>
    | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > microsoft.public.dotnet.framework.aspnet:115431
    | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > |
    | > | Thank you Steve on this.
    | > | Here is the code
    | > | Currently I implemented the property like this
    | > | [Browsable(true)]
    | > |
    | > | [Category("Appearance")]
    | > |
    | > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    | > typeof(UITypeEditor))]
    | > |
    | > | [DefaultValue("")]
    | > |
    | > | public string MiddleImageUrl
    | > |
    | > | {
    | > |
    | > | get
    | > |
    | > | {
    | > |
    | > | if(ViewState["MiddleImageUrl"]!=null)
    | > |
    | > | return ViewState["MiddleImageUrl"].ToString();
    | > |
    | > | else
    | > |
    | > | return middleImageUrl;
    | > |
    | > | }
    | > |
    | > | set
    | > |
    | > | {
    | > |
    | > | ViewState["MiddleImageUrl"]=value;
    | > |
    | > | middleImageUrl=value;
    | > |
    | > | }
    | > |
    | > | }
    | > |
    | > |
    | > |
    | > | The method that uses it is like this.
    | > |
    | > | protected override void CreateChildControls()
    | > |
    | > | {
    | > |
    | > |
    | > | Controls.Add(new LiteralControl("<table border =\"0\"
    | > | cellspacing=\"0\"><tr><td>"));
    | > |
    | > | Controls.Add(leftImage);
    | > |
    | > |
    | > | Controls.Add(new LiteralControl("</td><td width=\"100%\"
    | > | background=\""+MiddleImageUrl+"\">"));
    | > |
    | > | lblTitle.Width=Unit.Parse("100%");
    | > |
    | > | Controls.Add(lblTitle);
    | > |
    | > | Controls.Add(new LiteralControl("</td><td>"));
    | > |
    | > | Controls.Add(rightImage);
    | > |
    | > |
    | > |
    | > | Controls.Add(new LiteralControl("</td></tr>"));
    | > |
    | > | Controls.Add(new LiteralControl("<tr><td colspan=3>"));
    | > |
    | > | pnlBody.Width=Unit.Parse("100%");
    | > |
    | > | double height=this.Height.Value-lblTitle.Height.Value;
    | > |
    | > | pnlBody.Height=Unit.Parse(height.ToString());
    | > |
    | > | Controls.Add(pnlBody);
    | > |
    | > | Controls.Add(new LiteralControl("</td></td></table>"));
    | > |
    | > | }
    | > |
    | > | What I get is: I set up this property via VS.NET during design time
    | > |
    | > | at design time I see the image but at run time I don't have any image
    at
    | > | all - the field in html is blank.
    | > |
    | > | Thank you very much for help.
    | > |
    | > | "Steven Cheng[MSFT]" <> wrote in message
    | > | news:...
    | > | > Hi Shimon,
    | > | >
    | > | > Thanks for your response. As you said that
    | > | > " the problem is that I am trying to use it in CreateChildControls()
    | > | > method
    | > | > and then it not available"
    | > | >
    | > | > then, it still should be a runtime problem(not design-time). For
    | > ASP.NET
    | > | > Server Control, it'll pass through a certain sequence of events when
    | > being
    | > | > loaded into page on the serverside. And for composite control , the
    | > | > CreateChildControl will be called at certain time by the asp.net
    | > runtime.
    | > | > Generally, the first time page is requested, since there is no
    | > viewstate
    | > | > yet, the composite control's "CreateChildControls" maybe called
    after
    | > | > Page_Load and before PreRender. And when in the page's PostBack
    | > requests,
    | > | > since the page/controls need to restore states from ViewState, the
    | > | > composite control's "CreateChildControls" will be called before
    | > loading
    | > | > viewstate(dynamically created control will call LoadViewState after
    | > being
    | > | > added into parent collection).
    | > | >
    | > | > So, generally it's quite normal that we can't access the ViewState
    in
    | > | > CreateChildControl. Is there any particular requirement that you
    need
    | > to
    | > | > access viewstate in CreateChildControls? Generally, for composite
    | > | > control,
    | > | > the "CreatecontrolControls" method should contains the code that
    only
    | > | > constructing the basic control hierarchy. For manipulate Properites
    | > which
    | > | > persisted in ViewState, it is recommended to be put in postback
    event
    | > (at
    | > | > that time the viewstate has been successfully loaded).
    | > | >
    | > | > Please feel free to let me know if you have any particular problem
    or
    | > | > anything else unclear.
    | > | >
    | > | > Thanks & Regards,
    | > | >
    | > | > Steven Cheng
    | > | > Microsoft Online Support
    | > | >
    | > | > Get Secure! www.microsoft.com/security
    | > | > (This posting is provided "AS IS", with no warranties, and confers
    no
    | > | > rights.)
    | > | >
    | > | >
    | > | > --------------------
    | > | > | From: "Shimon Sim" <>
    | > | > | References: <>
    | > | > <>
    | > | > | Subject: Re: Custom Server Control Can't read design time property
    | > | > | Date: Fri, 29 Jul 2005 08:09:13 -0400
    | > | > | Lines: 122
    | > | > | X-Priority: 3
    | > | > | X-MSMail-Priority: Normal
    | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | > | > | X-RFC2646: Format=Flowed; Original
    | > | > | Message-ID: <>
    | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | > | Path:
    | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | > | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > | > microsoft.public.dotnet.framework.aspnet:115128
    | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > | > |
    | > | > | Thanks Steven.
    | > | > | I tried to use variable but it didn't work. I was thinking that
    | > could
    | > be
    | > | > the
    | > | > | problem is that I am trying to use it in CreateChildControls()
    | > method
    | > | > and
    | > | > | then it not available. Can you confirm my guess.
    | > | > | Thank you
    | > | > | Shimon.
    | > | > |
    | > | > | "Steven Cheng[MSFT]" <> wrote in
    message
    | > | > | news:...
    | > | > | > Hi Shimon,
    | > | > | >
    | > | > | > Welcome to ASPNET newsgroup.
    | > | > | > As for the Property of ASP.NET custom webserver control, they're
    | > | > processed
    | > | > | > differently between runtime and design-time. For those which
    | > | > store/persist
    | > | > | > the property in Viewstate, this only behave so at runtime where
    | > there
    | > | > is
    | > | > | > ViewState collection exists in memory. For design-time, the
    VS.NET
    | > IDE
    | > | > | > won't use the ViewState since there's no ASP.NET runtime
    exists.
    | > In
    | > | > | > design-time, all the value we set for the property in IDE will
    be
    | > | > | > persisted
    | > | > | > in the page template (aspx) according to our control's
    | > declaration.
    | > | > The
    | > | > | > "System.Web.UI.PersistenceModeAttribute" attribute is just to
    help
    | > | > define
    | > | > | > how to persist the control's property value at design-time, for
    | > | > example:
    | > | > | >
    | > | > | > [PersistenceMode(PersistenceMode.Attribute),
    | > | > | > public string Text
    | > | > | > {
    | > | > | > get ... set....
    | > | > | > }
    | > | > | >
    | > | > | > indicate the "Text" property's value will be persisted as an
    | > attribute
    | > | > in
    | > | > | > the Control's tag at design-time. This will result in the below
    | > conent
    | > | > in
    | > | > | > aspx page when we using the control:
    | > | > | >
    | > | > | > <prefix:ControlName id=xxxx Text="xxxx' ...../>
    | > | > | >
    | > | > | > Hope helps. Thanks,
    | > | > | >
    | > | > | > Steven Cheng
    | > | > | > Microsoft Online Support
    | > | > | >
    | > | > | > Get Secure! www.microsoft.com/security
    | > | > | > (This posting is provided "AS IS", with no warranties, and
    confers
    | > no
    | > | > | > rights.)
    | > | > | >
    | > | > | >
    | > | > | >
    | > | > | >
    | > | > | >
    | > | > | >
    | > | > | >
    | > | > | >
    | > | > | > --------------------
    | > | > | > | From: "Shimon Sim" <>
    | > | > | > | Subject: Custom Server Control Can't read design time property
    | > | > | > | Date: Thu, 28 Jul 2005 21:25:13 -0400
    | > | > | > | Lines: 48
    | > | > | > | X-Priority: 3
    | > | > | > | X-MSMail-Priority: Normal
    | > | > | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
    | > | > | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
    | > | > | > | X-RFC2646: Format=Flowed; Original
    | > | > | > | Message-ID: <>
    | > | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | > | > | > | NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
    | > | > | > | Path:
    | > | > TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | > | > | > | Xref: TK2MSFTNGXA01.phx.gbl
    | > | > | > microsoft.public.dotnet.framework.aspnet:115073
    | > | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    | > | > | > |
    | > | > | > | I have a custom composite control
    | > | > | > | I have following property
    | > | > | > |
    | > | > | > | [Browsable(true)]
    | > | > | > |
    | > | > | > | [Category("Appearance")]
    | > | > | > |
    | > | > | > | [Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
    | > | > | > typeof(UITypeEditor))]
    | > | > | > |
    | > | > | > | [DefaultValue("")]
    | > | > | > |
    | > | > | > | public string MiddleImageUrl
    | > | > | > |
    | > | > | > | {
    | > | > | > |
    | > | > | > | get
    | > | > | > |
    | > | > | > | {
    | > | > | > |
    | > | > | > | if(ViewState["MiddleImageUrl"]!=null)
    | > | > | > |
    | > | > | > | return ViewState["MiddleImageUrl"].ToString();
    | > | > | > |
    | > | > | > | else
    | > | > | > |
    | > | > | > | return null
    | > | > | > |
    | > | > | > | }
    | > | > | > |
    | > | > | > | set
    | > | > | > |
    | > | > | > | {
    | > | > | > |
    | > | > | > | ViewState["MiddleImageUrl"]=value;
    | > | > | > |
    | > | > | > | }
    | > | > | > |
    | > | > | > | }
    | > | > | > |
    | > | > | > | For some reason if I set up it up during design time it
    always
    | > "".
    | > | > | > |
    | > | > | > | I can't get why and what should I do to make it work.
    | > | > | > |
    | > | > | > | Thanks you
    | > | > | > |
    | > | > | > | Shimon.
    | > | > | > |
    | > | > | > |
    | > | > | > |
    | > | > | >
    | > | > |
    | > | > |
    | > | > |
    | > | >
    | > |
    | > |
    | > |
    | >
    |
    |
    |
    Steven Cheng[MSFT], Aug 3, 2005
    #8
    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. Replies:
    0
    Views:
    707
  2. Replies:
    1
    Views:
    358
    Teemu Keiski
    Jul 2, 2003
  3. vipul DotNet

    property is disabled at design time of my custom control

    vipul DotNet, Sep 15, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    196
    Sean Winstead
    Sep 15, 2003
  4. Mateus Padovani Velloso

    Web Custom Control, design-time property doesn't change attribute

    Mateus Padovani Velloso, Jan 11, 2005, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    239
    Mateus Padovani Velloso
    Feb 7, 2005
  5. Sebastián Streiger

    Custom Web Control Design-Time Property

    Sebastián Streiger, Oct 27, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    124
    Sebastián Streiger
    Oct 27, 2005
Loading...

Share This Page