Explicit Resource Expression

  • Thread starter Thread starter msnews.microsoft.com
  • Start date Start date
M

msnews.microsoft.com

I've converted a asp.net web project from VS 2005 to VS 2008. ASPX Web pages
are using explicit resource expression to retrieve label texts. Controls
using regular expression , VS 2008 design view displays complete expression
text like "Expression: ResourceFile,LabelLastSuccessfulLogin". This is
making really inconvenient to see the pages in design view and making
changes is really hard especially if you got a lot of labels using resource
expression. The whole page looks terrible as it messes up the alignment and
placement. VS 2005 allows to set text but not VS 2008 if text property is
being set through expression. Is there there any way to get around the issue
and avoid displaying expression in design view? Your help is greatly
appreciated.

Thanks
Vin
 
Hi Vin,

My name is Allen Chen. It's my pleasure to work with you on this issue.

The root cause of this issue is the designer of Label control. The designer
of Label control is LabelDesigner, which has an attribute
SupportsPreviewControl set to true. Visual studio sees this attribute and
render something like "Expression: ResourceFile,LabelLastSuccessfulLogin"
on the design view.

To work around this issue we can write a custom designer and use our custom
control instead of the Label control.

Below is the designer class:

namespace AllenChen.Designer.Helper
{

//When this designer is applied the ID of the control will be displayed
public class MyDesigner : LabelDesigner
{

}

//When this designer is applied we can change the displayed text via a new
//property DesignerText in the property window. Please note the control
using
//this designer must has DesignerText property.

public class MyDesigner2 : LabelDesigner
{
public override string GetDesignTimeHtml()
{

string designTimeHtml;
Control viewControl = base.ViewControl;
PropertyInfo property =
viewControl.GetType().GetProperty("DesignerText");
string str = (string)property.GetValue(viewControl, null);
if (str == null || str.Length == 0)
{
designTimeHtml = "You can change DesignerText via property
window";
}
else { designTimeHtml = str; }

return designTimeHtml;
}

}
}

And below is the control class:

[Designer("AllenChen.Designer.Helper.MyDesigner ,
AllenChen.Designer.Helper, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=f1fbaa4ed5a434d7")]
public class NewLabel:Label
{
}

[Designer("AllenChen.Designer.Helper.MyDesigner2 ,
AllenChen.Designer.Helper, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=f1fbaa4ed5a434d7")]
public class NewLabel2 : Label
{

public string DesignerText { get; set; }
}

You can also test the AllenChen.Designer.Helper project directly:

http://cid-2fa13ebc6cc8e80f.skydrive.live.com/self.aspx/Public/Newsgroup/All
enChen.Designer.Helper.zip

If you have other controls you can use the above way as well.

Please try it to see if it works and let me know if you have any further
questions.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 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. 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/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Vin,

Have you tried my code? Can it work?

Regards,
Allen Chen
Microsoft Online Community Support
 
Back
Top