Custom Server Control Can't read design time property

S

Shimon Sim

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.
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| 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: <[email protected]>
| 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.
|
|
|
 
S

Shimon Sim

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 said:
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" <[email protected]>
| 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: <[email protected]>
| 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.
|
|
|
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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.
|
| | > 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" <[email protected]>
| > | 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: <[email protected]>
| > | 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.
| > |
| > |
| > |
| >
|
|
|
 
S

Shimon Sim

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 said:
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" <[email protected]>
| References: <[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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.
|
| | > 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" <[email protected]>
| > | 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: <[email protected]>
| > | 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.
| > |
| > |
| > |
| >
|
|
|
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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.
|
| | > 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" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | 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: <[email protected]>
| > | 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.
| > |
| > | | > | > 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" <[email protected]>
| > | > | 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: <[email protected]>
| > | > | 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.
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
S

Shimon Sim

Thank you Steven
Shimon.
Steven Cheng said:
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" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| 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: <[email protected]>
| 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.
|
| | > 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" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > | 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: <[email protected]>
| > | 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.
| > |
| > | | > | > 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" <[email protected]>
| > | > | 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: <[email protected]>
| > | > | 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.
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 
S

Steven Cheng[MSFT]

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" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| 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: <#[email protected]>
| 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.
| | > 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" <[email protected]>
| > | References: <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > <[email protected]>
| > | 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: <[email protected]>
| > | 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.
| > |
| > | | > | > 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" <[email protected]>
| > | > | References: <[email protected]>
| > | > <[email protected]>
| > | > | 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: <[email protected]>
| > | > | 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.
| > | > |
message
| > | > | | > | > | > 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" <[email protected]>
| > | > | > | 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: <[email protected]>
| > | > | > | 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.
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top