473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom Server Control Can't read design time property

I have a custom composite control
I have following property

[Browsable(true)]

[Category("Appea rance")]

[Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor), typeof(UITypeEd itor))]

[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 2994
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. PersistenceMode Attribute" attribute is just to help define
how to persist the control's property value at design-time, for example:

[PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| I have a custom composite control
| I have following property
|
| [Browsable(true)]
|
| [Category("Appea rance")]
|
| [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
typeof(UITypeEd itor))]
|
| [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 CreateChildCont rols() 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******** ******@TK2MSFTN GXA01.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. PersistenceMode Attribute" attribute is just to help define
how to persist the control's property value at design-time, for example:

[PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| I have a custom composite control
| I have following property
|
| [Browsable(true)]
|
| [Category("Appea rance")]
|
| [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
typeof(UITypeEd itor))]
|
| [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 CreateChildCont rols() 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
CreateChildCont rol 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 "CreateChildCon trols" 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 "CreateChildCon trols" will be called before loading
viewstate(dynam ically 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
CreateChildCont rol. Is there any particular requirement that you need to
access viewstate in CreateChildCont rols? Generally, for composite control,
the "CreatecontrolC ontrols" 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**********@c ommunity.nospam >
| References: <ux************ *@TK2MSFTNGP09. phx.gbl>
<IV************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1151 28
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 CreateChildCont rols() 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******** ******@TK2MSFTN GXA01.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. PersistenceMode Attribute" attribute is just to help
define
| > how to persist the control's property value at design-time, for example:
| >
| > [PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | I have a custom composite control
| > | I have following property
| > |
| > | [Browsable(true)]
| > |
| > | [Category("Appea rance")]
| > |
| > | [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
| > typeof(UITypeEd itor))]
| > |
| > | [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("Appea rance")]

[Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor), typeof(UITypeEd itor))]

[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 CreateChildCont rols()

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

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

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

Controls.Add(lb lTitle);

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

Controls.Add(ri ghtImage);

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

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

pnlBody.Width=U nit.Parse("100% ");

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

pnlBody.Height= Unit.Parse(heig ht.ToString());

Controls.Add(pn lBody);

Controls.Add(ne w 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******** ******@TK2MSFTN GXA01.phx.gbl.. .
Hi Shimon,

Thanks for your response. As you said that
" the problem is that I am trying to use it in CreateChildCont rols()
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
CreateChildCont rol 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 "CreateChildCon trols" 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 "CreateChildCon trols" will be called before loading
viewstate(dynam ically 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
CreateChildCont rol. Is there any particular requirement that you need to
access viewstate in CreateChildCont rols? Generally, for composite
control,
the "CreatecontrolC ontrols" 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**********@c ommunity.nospam >
| References: <ux************ *@TK2MSFTNGP09. phx.gbl>
<IV************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1151 28
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 CreateChildCont rols() 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******** ******@TK2MSFTN GXA01.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. PersistenceMode Attribute" attribute is just to help
define
| > how to persist the control's property value at design-time, for
example:
| >
| > [PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | I have a custom composite control
| > | I have following property
| > |
| > | [Browsable(true)]
| > |
| > | [Category("Appea rance")]
| > |
| > | [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
| > typeof(UITypeEd itor))]
| > |
| > | [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
CreateChildCont rol method, as I've mentioend in the last reply, since the
CreateChildCont rol 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 "CreateChildCon trols" 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**********@c ommunity.nospam >
| References: <ux************ *@TK2MSFTNGP09. phx.gbl>
<IV************ **@TK2MSFTNGXA0 1.phx.gbl>
<ea************ **@TK2MSFTNGP09 .phx.gbl>
<cA************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1154 31
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thank you Steve on this.
| Here is the code
| Currently I implemented the property like this
| [Browsable(true)]
|
| [Category("Appea rance")]
|
| [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
typeof(UITypeEd itor))]
|
| [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 CreateChildCont rols()
|
| {
|
|
| Controls.Add(ne w LiteralControl( "<table border =\"0\"
| cellspacing=\"0 \"><tr><td>" ));
|
| Controls.Add(le ftImage);
|
|
| Controls.Add(ne w LiteralControl( "</td><td width=\"100%\"
| background=\""+ MiddleImageUrl+ "\">"));
|
| lblTitle.Width= Unit.Parse("100 %");
|
| Controls.Add(lb lTitle);
|
| Controls.Add(ne w LiteralControl( "</td><td>"));
|
| Controls.Add(ri ghtImage);
|
|
|
| Controls.Add(ne w LiteralControl( "</td></tr>"));
|
| Controls.Add(ne w LiteralControl( "<tr><td colspan=3>"));
|
| pnlBody.Width=U nit.Parse("100% ");
|
| double height=this.Hei ght.Value-lblTitle.Height .Value;
|
| pnlBody.Height= Unit.Parse(heig ht.ToString());
|
| Controls.Add(pn lBody);
|
| Controls.Add(ne w 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******** ******@TK2MSFTN GXA01.phx.gbl.. .
| > Hi Shimon,
| >
| > Thanks for your response. As you said that
| > " the problem is that I am trying to use it in CreateChildCont rols()
| > 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
| > CreateChildCont rol 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 "CreateChildCon trols" 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 "CreateChildCon trols" will be called before loading
| > viewstate(dynam ically 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
| > CreateChildCont rol. Is there any particular requirement that you need to
| > access viewstate in CreateChildCont rols? Generally, for composite
| > control,
| > the "CreatecontrolC ontrols" 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**********@c ommunity.nospam >
| > | References: <ux************ *@TK2MSFTNGP09. phx.gbl>
| > <IV************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1151 28
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 CreateChildCont rols() 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******** ******@TK2MSFTN GXA01.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. PersistenceMode Attribute" attribute is just to help
| > define
| > | > how to persist the control's property value at design-time, for
| > example:
| > | >
| > | > [PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| > | > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | > | Path:
| > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | > | Xref: TK2MSFTNGXA01.p hx.gbl
| > | > microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| > | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > | > |
| > | > | I have a custom composite control
| > | > | I have following property
| > | > |
| > | > | [Browsable(true)]
| > | > |
| > | > | [Category("Appea rance")]
| > | > |
| > | > | [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
| > | > typeof(UITypeEd itor))]
| > | > |
| > | > | [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******** ******@TK2MSFTN GXA01.phx.gbl.. .
Thanks for your further followup Shimon,

From the code you provided , you retrieve the url info from ViewState in
CreateChildCont rol method, as I've mentioend in the last reply, since the
CreateChildCont rol 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 "CreateChildCon trols" 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**********@c ommunity.nospam >
| References: <ux************ *@TK2MSFTNGP09. phx.gbl>
<IV************ **@TK2MSFTNGXA0 1.phx.gbl>
<ea************ **@TK2MSFTNGP09 .phx.gbl>
<cA************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1154 31
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thank you Steve on this.
| Here is the code
| Currently I implemented the property like this
| [Browsable(true)]
|
| [Category("Appea rance")]
|
| [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
typeof(UITypeEd itor))]
|
| [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 CreateChildCont rols()
|
| {
|
|
| Controls.Add(ne w LiteralControl( "<table border =\"0\"
| cellspacing=\"0 \"><tr><td>" ));
|
| Controls.Add(le ftImage);
|
|
| Controls.Add(ne w LiteralControl( "</td><td width=\"100%\"
| background=\""+ MiddleImageUrl+ "\">"));
|
| lblTitle.Width= Unit.Parse("100 %");
|
| Controls.Add(lb lTitle);
|
| Controls.Add(ne w LiteralControl( "</td><td>"));
|
| Controls.Add(ri ghtImage);
|
|
|
| Controls.Add(ne w LiteralControl( "</td></tr>"));
|
| Controls.Add(ne w LiteralControl( "<tr><td colspan=3>"));
|
| pnlBody.Width=U nit.Parse("100% ");
|
| double height=this.Hei ght.Value-lblTitle.Height .Value;
|
| pnlBody.Height= Unit.Parse(heig ht.ToString());
|
| Controls.Add(pn lBody);
|
| Controls.Add(ne w 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******** ******@TK2MSFTN GXA01.phx.gbl.. .
| > Hi Shimon,
| >
| > Thanks for your response. As you said that
| > " the problem is that I am trying to use it in CreateChildCont rols()
| > 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
| > CreateChildCont rol 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 "CreateChildCon trols" 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 "CreateChildCon trols" will be called before
loading
| > viewstate(dynam ically 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
| > CreateChildCont rol. Is there any particular requirement that you need
to
| > access viewstate in CreateChildCont rols? Generally, for composite
| > control,
| > the "CreatecontrolC ontrols" 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**********@c ommunity.nospam >
| > | References: <ux************ *@TK2MSFTNGP09. phx.gbl>
| > <IV************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | Path:
TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1151 28
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 CreateChildCont rols()
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******** ******@TK2MSFTN GXA01.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. PersistenceMode Attribute" attribute is just to help
| > define
| > | > how to persist the control's property value at design-time, for
| > example:
| > | >
| > | > [PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| > | > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | > | Path:
| > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | > | Xref: TK2MSFTNGXA01.p hx.gbl
| > | > microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| > | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > | > |
| > | > | I have a custom composite control
| > | > | I have following property
| > | > |
| > | > | [Browsable(true)]
| > | > |
| > | > | [Category("Appea rance")]
| > | > |
| > | > | [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
| > | > typeof(UITypeEd itor))]
| > | > |
| > | > | [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**********@c ommunity.nospam >
| References: <ux************ *@TK2MSFTNGP09. phx.gbl>
<IV************ **@TK2MSFTNGXA0 1.phx.gbl>
<ea************ **@TK2MSFTNGP09 .phx.gbl>
<cA************ **@TK2MSFTNGXA0 1.phx.gbl>
<OA************ **@TK2MSFTNGP10 .phx.gbl>
<8c************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP12.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1156 13
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thank you Steven
| Shimon.
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:8c******** ******@TK2MSFTN GXA01.phx.gbl.. .
| > Thanks for your further followup Shimon,
| >
| > From the code you provided , you retrieve the url info from ViewState in
| > CreateChildCont rol method, as I've mentioend in the last reply, since
the
| > CreateChildCont rol 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 "CreateChildCon trols" 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**********@c ommunity.nospam >
| > | References: <ux************ *@TK2MSFTNGP09. phx.gbl>
| > <IV************ **@TK2MSFTNGXA0 1.phx.gbl>
| > <ea************ **@TK2MSFTNGP09 .phx.gbl>
| > <cA************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP10.phx. gbl
| > | Xref: TK2MSFTNGXA01.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:1154 31
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | Thank you Steve on this.
| > | Here is the code
| > | Currently I implemented the property like this
| > | [Browsable(true)]
| > |
| > | [Category("Appea rance")]
| > |
| > | [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
| > typeof(UITypeEd itor))]
| > |
| > | [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 CreateChildCont rols()
| > |
| > | {
| > |
| > |
| > | Controls.Add(ne w LiteralControl( "<table border =\"0\"
| > | cellspacing=\"0 \"><tr><td>" ));
| > |
| > | Controls.Add(le ftImage);
| > |
| > |
| > | Controls.Add(ne w LiteralControl( "</td><td width=\"100%\"
| > | background=\""+ MiddleImageUrl+ "\">"));
| > |
| > | lblTitle.Width= Unit.Parse("100 %");
| > |
| > | Controls.Add(lb lTitle);
| > |
| > | Controls.Add(ne w LiteralControl( "</td><td>"));
| > |
| > | Controls.Add(ri ghtImage);
| > |
| > |
| > |
| > | Controls.Add(ne w LiteralControl( "</td></tr>"));
| > |
| > | Controls.Add(ne w LiteralControl( "<tr><td colspan=3>"));
| > |
| > | pnlBody.Width=U nit.Parse("100% ");
| > |
| > | double height=this.Hei ght.Value-lblTitle.Height .Value;
| > |
| > | pnlBody.Height= Unit.Parse(heig ht.ToString());
| > |
| > | Controls.Add(pn lBody);
| > |
| > | Controls.Add(ne w 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******** ******@TK2MSFTN GXA01.phx.gbl.. .
| > | > Hi Shimon,
| > | >
| > | > Thanks for your response. As you said that
| > | > " the problem is that I am trying to use it in CreateChildCont rols()
| > | > 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
| > | > CreateChildCont rol 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 "CreateChildCon trols" 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 "CreateChildCon trols" will be called before
| > loading
| > | > viewstate(dynam ically 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
| > | > CreateChildCont rol. Is there any particular requirement that you
need
| > to
| > | > access viewstate in CreateChildCont rols? Generally, for composite
| > | > control,
| > | > the "CreatecontrolC ontrols" 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**********@c ommunity.nospam >
| > | > | References: <ux************ *@TK2MSFTNGP09. phx.gbl>
| > | > <IV************ **@TK2MSFTNGXA0 1.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.publi c.dotnet.framew ork.aspnet
| > | > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | > | Path:
| > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | > | Xref: TK2MSFTNGXA01.p hx.gbl
| > | > microsoft.publi c.dotnet.framew ork.aspnet:1151 28
| > | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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 CreateChildCont rols()
| > 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******** ******@TK2MSFTN GXA01.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. PersistenceMode Attribute" attribute is just to
help
| > | > define
| > | > | > how to persist the control's property value at design-time, for
| > | > example:
| > | > | >
| > | > | > [PersistenceMode (PersistenceMod e.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:Control Name 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**********@c ommunity.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.publi c.dotnet.framew ork.aspnet
| > | > | > | NNTP-Posting-Host: ool-44c05922.dyn.op tonline.net 68.192.89.34
| > | > | > | Path:
| > | > TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | > | > | Xref: TK2MSFTNGXA01.p hx.gbl
| > | > | > microsoft.publi c.dotnet.framew ork.aspnet:1150 73
| > | > | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > | > | > |
| > | > | > | I have a custom composite control
| > | > | > | I have following property
| > | > | > |
| > | > | > | [Browsable(true)]
| > | > | > |
| > | > | > | [Category("Appea rance")]
| > | > | > |
| > | > | > | [Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
| > | > | > typeof(UITypeEd itor))]
| > | > | > |
| > | > | > | [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
12501
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 directly derived from the .net classes ComboBox and TextBox) I did the custom control in the visual studio .net designer in which i
2
3193
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp The problem I am having is that the data in the custom datagridcolumn is not saved to viewstate and after postback, the column does not contain data.
0
3259
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 time. If I type the code in the aspx manually it does get parsed correctly though. This is an example of the aspx code that gets parsed correctly. For some reason, if I changed update the Tab property of the control through the GUI at design...
3
7799
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 control can set the event handler from this tab. However, I can't see my custom StateChanged event over there and I don't know what is the reason. Setting BrowsableAttribute to the public event property doesn't solve the problem. Any other ideas? ...
0
1601
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 correctly. If I change to HTML the generated html is <cc1:IT24DateTime id="IT24DateTime1" runat="server" Type="Date"></cc1:IT24DateTime> .... and that works correctly.
0
1346
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 textbox control which has a ‘TextMode’ property and when clicked on, displays as a dropdown list with 3 values, I want to have a similar type property with a dropdown style. So far, I have a property defined which displays the dropdown arrow...
0
1610
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 textbox control which has a 'TextMode' property and when clicked on, displays as a dropdown list with 3 values, I want to have a similar type property with a dropdown style.
15
6512
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 accept other controls. The control i drag drop on it becomes the child of my custom control's parent form and not the child of my custom control. Then i added this line "" before my custom control class (i dont know what this line does). Now
5
4117
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 to wrap the control in the proper control type - which is also a container. At design time I want to be able to turn this : <my:container> <asp:textbox />
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2329
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.