[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Setting Inner Tag Content at Design Time programmatically

Nathaniel Greene

1/20/2007 6:57:00 AM

I am creating a web control. At design time I would like the designer to
inspect the control being hosted, to see if there is any inner content and if
there isn't then programmatically set the server control's markup.
for example <My:Control runat="server"></My:Control> would be changed to
<My:Control runat="server">Some markup</My:Control>
if SetEditableDesignerRegionContent is called by the designer the markup is
changed.
If I call it myself, however it's not changed. The same appears to be true
for Tag.SetContent and almost every other imaginable sample I've seen on the
web.

I have to assume that for a very basic procedure that I am simply missing
something. Tag.SetContent seems to do what i need it to do, except it won't
work if I call it.

Any tips?


18 Answers

wawang

1/22/2007 9:21:00 AM

0

Hi Nathaniel,

Based on my understanding, you have a custom server control which has
ParseChildrenAttribute set to false and PersistChildrenAttribute set to
true:

[ParseChildren(false), PersistChildren(true)]
public class Class1 : WebControl
{
}

This will let user add content inside the control tag:

<cc1:Class1 ID="Class1_1" runat="server">
test
</cc1:Class1>

The objective is to add this default content when user didn't provide one.
Please feel free to let me know if I've misunderstood anything.


Currently I'm still researching on it and I will get back to you as soon as
possible. Thank you for your patience and understanding.


Sincerely,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/de....
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nathaniel Greene

1/22/2007 4:01:00 PM

0

That is correct. I'm basically wanting to provide a "default interface" for
the user, but allow the user to easily customize the interface should he/she
need to.

Thanks

"Walter Wang [MSFT]" wrote:

> Hi Nathaniel,
>
> Based on my understanding, you have a custom server control which has
> ParseChildrenAttribute set to false and PersistChildrenAttribute set to
> true:
>
> [ParseChildren(false), PersistChildren(true)]
> public class Class1 : WebControl
> {
> }
>
> This will let user add content inside the control tag:
>
> <cc1:Class1 ID="Class1_1" runat="server">
> test
> </cc1:Class1>
>
> The objective is to add this default content when user didn't provide one.
> Please feel free to let me know if I've misunderstood anything.
>
>
> Currently I'm still researching on it and I will get back to you as soon as
> possible. Thank you for your patience and understanding.
>
>
> Sincerely,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default....
> ications. If you are using Outlook Express, please make sure you clear the
> check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
> promptly.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/de....
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

wawang

1/24/2007 12:46:00 AM

0

Hi Nathaniel,

To provide a default content in the inner tag, you need to create your own
control designer and override the method GetPersistenceContent():

public class Class1Designer : ControlDesigner
{
public override string GetPersistenceContent()
{
return "default content";
}
}

[ParseChildren(false), PersistChildren(true),
Designer(typeof(Class1Designer))]
public class Class1 : WebControl
{
}


Note this only works if the control is drag&dropped from toolbox to the
designer surface. If the control is manually written or dropped to the
source view, the default content will not be used. Also, when you dropped
the control to the designer surface, you need to refresh (menu
view/refresh, or right-click and select refresh) to see the default
content, but the source view actually already has the default content.

Let me know if you have any questions.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Nathaniel Greene

1/24/2007 4:31:00 AM

0

That is not really what I want. Im looking for a way to set this when ever
the designer initializes and determines that there is no inner content.

The reason for this is because there are many issues, such as recently due
to Microsofts SP1 for VS2k5 update I can no longer drag and drop my custom
web controls from the toolbox), that will prevent a user from being able to
drag and drop. Also a user may wish to reset the content to default and in
both situations the Designer has to be able to set the Inner Content. I
cannot believe that something that Visual studio does all the time is not
capable of being user invoked from the designer.

"Walter Wang [MSFT]" wrote:

> Hi Nathaniel,
>
> To provide a default content in the inner tag, you need to create your own
> control designer and override the method GetPersistenceContent():
>
> public class Class1Designer : ControlDesigner
> {
> public override string GetPersistenceContent()
> {
> return "default content";
> }
> }
>
> [ParseChildren(false), PersistChildren(true),
> Designer(typeof(Class1Designer))]
> public class Class1 : WebControl
> {
> }
>
>
> Note this only works if the control is drag&dropped from toolbox to the
> designer surface. If the control is manually written or dropped to the
> source view, the default content will not be used. Also, when you dropped
> the control to the designer surface, you need to refresh (menu
> view/refresh, or right-click and select refresh) to see the default
> content, but the source view actually already has the default content.
>
> Let me know if you have any questions.
>
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>

Nathaniel Greene

1/26/2007 2:26:00 AM

0

Any updates?

"Nathaniel Greene" wrote:

> That is not really what I want. Im looking for a way to set this when ever
> the designer initializes and determines that there is no inner content.
>
> The reason for this is because there are many issues, such as recently due
> to Microsofts SP1 for VS2k5 update I can no longer drag and drop my custom
> web controls from the toolbox), that will prevent a user from being able to
> drag and drop. Also a user may wish to reset the content to default and in
> both situations the Designer has to be able to set the Inner Content. I
> cannot believe that something that Visual studio does all the time is not
> capable of being user invoked from the designer.
>
> "Walter Wang [MSFT]" wrote:
>
> > Hi Nathaniel,
> >
> > To provide a default content in the inner tag, you need to create your own
> > control designer and override the method GetPersistenceContent():
> >
> > public class Class1Designer : ControlDesigner
> > {
> > public override string GetPersistenceContent()
> > {
> > return "default content";
> > }
> > }
> >
> > [ParseChildren(false), PersistChildren(true),
> > Designer(typeof(Class1Designer))]
> > public class Class1 : WebControl
> > {
> > }
> >
> >
> > Note this only works if the control is drag&dropped from toolbox to the
> > designer surface. If the control is manually written or dropped to the
> > source view, the default content will not be used. Also, when you dropped
> > the control to the designer surface, you need to refresh (menu
> > view/refresh, or right-click and select refresh) to see the default
> > content, but the source view actually already has the default content.
> >
> > Let me know if you have any questions.
> >
> >
> > Regards,
> > Walter Wang (wawang@online.microsoft.com, remove 'online.')
> > Microsoft Online Community Support
> >
> > ==================================================
> > When responding to posts, please "Reply to Group" via your newsreader so
> > that others may learn and benefit from your issue.
> > ==================================================
> >
> > This posting is provided "AS IS" with no warranties, and confers no rights.
> >
> >
> >

wawang

1/26/2007 7:08:00 AM

0

Hi Nathaniel,

Sorry for late reply. I was discussing your question with product team to
see if there're any other approaches.

In VS2005 the ControlDesigners effectively are only running while in design
view. That's why the GetPersistenceContent() only is effective when the
control is dropped on the designer surface. There're are other ways of
customizing the content of a control when it's drag/dropped such as using
the ToolboxDataAttribute. However this also only is effective when the
control gets first dropped.

Would you please tell me about your requirement? I think setting the
default initial value will be better for user experience. I mean, if I'm
the user and I removed the content and later found the content is filled
with other content again, I will be surprised.


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

wawang

1/26/2007 7:54:00 AM

0

Hi Nathaniel,

If you could describe your specific requirements detailly, we may find
other approach for your objective. Thanks.

Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nathaniel Greene

1/26/2007 9:37:00 PM

0

The control could most similary be compared to the "LoginView" that is part
of the asp.net web parts.
The control should be pre-populated with markup extracted from our
templates. The user has to be able to customize the content however, the user
should be able to reset the contents to the default template. Also, the
control has to be able to be populated if the user types the control manually
because he is unable to drag and drop.

I can't believe that all of ms's designers can do this. This is the basis
for everything, such as an <asp:ListItem's ListItem editing. adding columns
to a datagrid.
There has to be some flag or method that tells the designer to serialize the
content now because all of ms's controls can do it.



"Walter Wang [MSFT]" wrote:

> Hi Nathaniel,
>
> If you could describe your specific requirements detailly, we may find
> other approach for your objective. Thanks.
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

wawang

1/27/2007 9:18:00 AM

0

Hi Nathaniel,

It seems I may have misunderstood your question at the very beginning. Are
you referring to Region-based Editing in ASP.NET Designer support? If this
is the case, you can find an example here:

#Panel Container with Styled and Region-based - The Code Project - ASP.NET
http://www.codeproject.com/useritems/shSimpl...


Regarding "<asp:ListItem's ListItem editing", I believe you're referring to
the CollectionEditor:

#Collection Editor Example
http://msdn2.microsoft.com/en-us/library/9zk...


Regards,
Walter Wang (wawang@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Nathaniel Greene

1/27/2007 4:36:00 PM

0

Yes I've already seen that example but no that doesn't do what I want it to
do.
Yes part of the region is going to be editable, but I've already
accomplished this.

What I am trying to do is this.

I have a control <my:PagesView></my:PagesView>
When a user drags it from the toolbox or types <my:PagesView and switches to
the designer
there is no content in there. The Designer checks to see if there is any
content. If there is no content it grabs the default template that shows up
here and sticks it in here. ( This is what I'm trying to do).

The user then makes edits to the content. Then he decides to reset the
template because he made a mistake. So he clicks a DesignerVerb link that
resets the content to the template default.

I listed the other items for reference because, they can do what I can't
seem to do.
When you edit a collection in an Design Time, for example, adding multiple
ListItems in an asp:DropDown - These Items are serialized INSTANTLY.

WHY CANT I FORCE THE DESIGNER TO SERIALIZE THE CONTENTS OF MY ITEMPLATE SO
THEY APPEAR IN THE MARKUP. Everybody else can but I can't? Why not?



"Walter Wang [MSFT]" wrote:

> Hi Nathaniel,
>
> It seems I may have misunderstood your question at the very beginning. Are
> you referring to Region-based Editing in ASP.NET Designer support? If this
> is the case, you can find an example here:
>
> #Panel Container with Styled and Region-based - The Code Project - ASP.NET
> http://www.codeproject.com/useritems/shSimpl...
>
>
> Regarding "<asp:ListItem's ListItem editing", I believe you're referring to
> the CollectionEditor:
>
> #Collection Editor Example
> http://msdn2.microsoft.com/en-us/library/9zk...
>
>
> Regards,
> Walter Wang (wawang@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>