472,808 Members | 3,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,808 software developers and data experts.

Custom Server Control Can't read design time property

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.
Nov 19 '05 #1
7 2882
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" <sh**********@community.nospam>
| 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSFT NGP09.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.
|
|
|

Nov 19 '05 #2
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]" <st*****@online.microsoft.com> wrote in message
news:IV**************@TK2MSFTNGXA01.phx.gbl...
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" <sh**********@community.nospam>
| 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSFT NGP09.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.
|
|
|

Nov 19 '05 #3
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" <sh**********@community.nospam>
| References: <ux*************@TK2MSFTNGP09.phx.gbl>
<IV**************@TK2MSFTNGXA01.phx.gbl>
| 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: <ea**************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSFT NGP09.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]" <st*****@online.microsoft.com> wrote in message
| news:IV**************@TK2MSFTNGXA01.phx.gbl...
| > 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" <sh**********@community.nospam>
| > | 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| > | 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!TK2MSFT NGP09.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.
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #4
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]" <st*****@online.microsoft.com> wrote in message
news:cA**************@TK2MSFTNGXA01.phx.gbl...
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" <sh**********@community.nospam>
| References: <ux*************@TK2MSFTNGP09.phx.gbl>
<IV**************@TK2MSFTNGXA01.phx.gbl>
| 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: <ea**************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSFT NGP09.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]" <st*****@online.microsoft.com> wrote in message
| news:IV**************@TK2MSFTNGXA01.phx.gbl...
| > 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" <sh**********@community.nospam>
| > | 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| > | 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!TK2MSFT NGP09.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.
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #5
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" <sh**********@community.nospam>
| References: <ux*************@TK2MSFTNGP09.phx.gbl>
<IV**************@TK2MSFTNGXA01.phx.gbl>
<ea**************@TK2MSFTNGP09.phx.gbl>
<cA**************@TK2MSFTNGXA01.phx.gbl>
| 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: <OA**************@TK2MSFTNGP10.phx.gbl>
| 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!TK2MSFT NGP10.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]" <st*****@online.microsoft.com> wrote in message
| news:cA**************@TK2MSFTNGXA01.phx.gbl...
| > 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" <sh**********@community.nospam>
| > | References: <ux*************@TK2MSFTNGP09.phx.gbl>
| > <IV**************@TK2MSFTNGXA01.phx.gbl>
| > | 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: <ea**************@TK2MSFTNGP09.phx.gbl>
| > | 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!TK2MSFT NGP09.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]" <st*****@online.microsoft.com> wrote in message
| > | news:IV**************@TK2MSFTNGXA01.phx.gbl...
| > | > 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" <sh**********@community.nospam>
| > | > | 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| > | > | 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!TK2MSFT NGP09.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.
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #6
Thank you Steven
Shimon.
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:8c**************@TK2MSFTNGXA01.phx.gbl...
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" <sh**********@community.nospam>
| References: <ux*************@TK2MSFTNGP09.phx.gbl>
<IV**************@TK2MSFTNGXA01.phx.gbl>
<ea**************@TK2MSFTNGP09.phx.gbl>
<cA**************@TK2MSFTNGXA01.phx.gbl>
| 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: <OA**************@TK2MSFTNGP10.phx.gbl>
| 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!TK2MSFT NGP10.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]" <st*****@online.microsoft.com> wrote in message
| news:cA**************@TK2MSFTNGXA01.phx.gbl...
| > 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" <sh**********@community.nospam>
| > | References: <ux*************@TK2MSFTNGP09.phx.gbl>
| > <IV**************@TK2MSFTNGXA01.phx.gbl>
| > | 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: <ea**************@TK2MSFTNGP09.phx.gbl>
| > | 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!TK2MSFT NGP09.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]" <st*****@online.microsoft.com> wrote in message
| > | news:IV**************@TK2MSFTNGXA01.phx.gbl...
| > | > 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" <sh**********@community.nospam>
| > | > | 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| > | > | 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!TK2MSFT NGP09.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.
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #7
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" <sh**********@community.nospam>
| References: <ux*************@TK2MSFTNGP09.phx.gbl>
<IV**************@TK2MSFTNGXA01.phx.gbl>
<ea**************@TK2MSFTNGP09.phx.gbl>
<cA**************@TK2MSFTNGXA01.phx.gbl>
<OA**************@TK2MSFTNGP10.phx.gbl>
<8c**************@TK2MSFTNGXA01.phx.gbl>
| 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: <#m**************@TK2MSFTNGP12.phx.gbl>
| 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!TK2MSFT NGP12.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]" <st*****@online.microsoft.com> wrote in message
| news:8c**************@TK2MSFTNGXA01.phx.gbl...
| > 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" <sh**********@community.nospam>
| > | References: <ux*************@TK2MSFTNGP09.phx.gbl>
| > <IV**************@TK2MSFTNGXA01.phx.gbl>
| > <ea**************@TK2MSFTNGP09.phx.gbl>
| > <cA**************@TK2MSFTNGXA01.phx.gbl>
| > | 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: <OA**************@TK2MSFTNGP10.phx.gbl>
| > | 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!TK2MSFT NGP10.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]" <st*****@online.microsoft.com> wrote in message
| > | news:cA**************@TK2MSFTNGXA01.phx.gbl...
| > | > 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" <sh**********@community.nospam>
| > | > | References: <ux*************@TK2MSFTNGP09.phx.gbl>
| > | > <IV**************@TK2MSFTNGXA01.phx.gbl>
| > | > | 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: <ea**************@TK2MSFTNGP09.phx.gbl>
| > | > | 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!TK2MSFT NGP09.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]" <st*****@online.microsoft.com> wrote in
message
| > | > | news:IV**************@TK2MSFTNGXA01.phx.gbl...
| > | > | > 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" <sh**********@community.nospam>
| > | > | > | 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: <ux*************@TK2MSFTNGP09.phx.gbl>
| > | > | > | 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!TK2MSFT NGP09.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.
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Martin Schulze | last post by:
Hello, i tried to compose myself a custom usercontrol which is derieved from System.Windows.Forms.UserControl. It contains 2 comboboxes and one textbox (which are also custom controls, but...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
3
by: George Jordanov Ivanov | last post by:
Folks, I am implementing a WebUserControl, which will have its own custom event StateChanged. Now, I want to add this event to the Events tab in the control properties, so that the users of my...
0
by: pabloazorin | last post by:
I developed a Date Picker web control using C# and .net framework 1.1 I added my control to Visual Studio 2003 IDE toolbar. When I drag and drop my control to design web page, the control renders...
0
by: Kay | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
0
by: Kay O'Keeffe | last post by:
Hello, I have written my own custom control and I want one of its properties to display as a dropdown list when clicked, so the user can select from the list, it would be similar to the asp...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
5
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.