Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Custom Server Control Can't read design time property

Reply
Thread Tools

Custom Server Control Can't read design time property

 
 
Shimon Sim
Guest
Posts: n/a
 
      07-29-2005
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.


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      07-29-2005
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" <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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.
|
|
|

 
Reply With Quote
 
 
 
 
Shimon Sim
Guest
Posts: n/a
 
      07-29-2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> | 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: <(E-Mail Removed)>
> | 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.
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-01-2005
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" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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" <(E-Mail Removed)>
| > | 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: <(E-Mail Removed)>
| > | 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.
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
Shimon Sim
Guest
Posts: n/a
 
      08-01-2005
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> | References: <(E-Mail Removed)>
> <(E-Mail Removed)>
> | 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: <(E-Mail Removed)>
> | 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]" <(E-Mail Removed)> wrote in message
> | news:(E-Mail Removed)...
> | > 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" <(E-Mail Removed)>
> | > | 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: <(E-Mail Removed)>
> | > | 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.
> | > |
> | > |
> | > |
> | >
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-02-2005
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" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:(E-Mail Removed)...
| > 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" <(E-Mail Removed)>
| > | References: <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > | 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: <(E-Mail Removed)>
| > | 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]" <(E-Mail Removed)> wrote in message
| > | news:(E-Mail Removed)...
| > | > 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" <(E-Mail Removed)>
| > | > | 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: <(E-Mail Removed)>
| > | > | 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.
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
Shimon Sim
Guest
Posts: n/a
 
      08-02-2005
Thank you Steven
Shimon.
"Steven Cheng[MSFT]" <(E-Mail Removed)> wrote in message
news:8c$(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> | References: <(E-Mail Removed)>
> <(E-Mail Removed)>
> <(E-Mail Removed)>
> <(E-Mail Removed)>
> | 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: <(E-Mail Removed)>
> | 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]" <(E-Mail Removed)> wrote in message
> | news:(E-Mail Removed)...
> | > 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" <(E-Mail Removed)>
> | > | References: <(E-Mail Removed)>
> | > <(E-Mail Removed)>
> | > | 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: <(E-Mail Removed)>
> | > | 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]" <(E-Mail Removed)> wrote in message
> | > | news:(E-Mail Removed)...
> | > | > 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" <(E-Mail Removed)>
> | > | > | 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: <(E-Mail Removed)>
> | > | > | 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.
> | > | > |
> | > | > |
> | > | > |
> | > | >
> | > |
> | > |
> | > |
> | >
> |
> |
> |
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-03-2005
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" <(E-Mail Removed)>
| References: <(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<(E-Mail Removed)>
<8c$(E-Mail Removed)>
| 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: <#(E-Mail Removed)>
| 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]" <(E-Mail Removed)> wrote in message
| news:8c$(E-Mail Removed)...
| > 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" <(E-Mail Removed)>
| > | References: <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > <(E-Mail Removed)>
| > | 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: <(E-Mail Removed)>
| > | 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]" <(E-Mail Removed)> wrote in message
| > | news:(E-Mail Removed)...
| > | > 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" <(E-Mail Removed)>
| > | > | References: <(E-Mail Removed)>
| > | > <(E-Mail Removed)>
| > | > | 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: <(E-Mail Removed)>
| > | > | 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]" <(E-Mail Removed)> wrote in
message
| > | > | news:(E-Mail Removed)...
| > | > | > 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" <(E-Mail Removed)>
| > | > | > | 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: <(E-Mail Removed)>
| > | > | > | 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.
| > | > | > |
| > | > | > |
| > | > | > |
| > | > | >
| > | > |
| > | > |
| > | > |
| > | >
| > |
| > |
| > |
| >
|
|
|

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Web Control Design-Time Property Sebastián Streiger ASP .Net Building Controls 0 10-27-2005 08:16 PM
Web Custom Control, design-time property doesn't change attribute Mateus Padovani Velloso ASP .Net Building Controls 2 02-07-2005 12:41 AM
property is disabled at design time of my custom control vipul DotNet ASP .Net Building Controls 1 09-15-2003 02:22 PM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net Building Controls 1 07-02-2003 08:05 AM
Using Table control in a custom composite control. Control does not render properly in design time. jb_in_marietta@yahoo.com ASP .Net 0 07-01-2003 09:26 PM



Advertisments