need locale hyperlink help filename

G

Guest

Hi;

I have help html pages for each page of my ASP.NET webapp. So for the page
datasource.aspx, I have help\datasource.htm.

Bu what I want when the hyperlink is clicked, for it to look for the
following files in order (assuming I am running from the us):
help\datasource_en_US.htm
help\datasource_en.htm
help\datasource.htm

So that based on the client user's locale, I am getting them the best
language fit we have. Is there any easy way to do this? Or do I need to set
these in the page load?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

John Timney \(MVP\)

Why dont you set the hyperlink instead to the correct URL based on their
country code, or have them all access the same help file when they click the
hyperlink and put logic in that to determine where to server.transfer them
onto, which could look for the correct local file if you had one prior to
doing the transfer.

Regards

John Timney (MVP)
VISIT MY WEBSITE:
http://www.johntimney.com
 
M

Mark Fitzpatrick

I believe, since you're making it a link, you'll have to do all the logic
for that first. There's no real way to have the link handle that itself.

Have you given some though though to using the built in globalization
features? Instead of having three seperate HTML files, you could create
resource strings and let the globalization feature try to figure out which
resource string to use based on the current user's culture selection and
simply dump that text into a literal control. That would really help you
avoid some messy logic for trying to figure out the link beforehand and pass
it off instead to the globalization features.
 
W

Walter Wang [MSFT]

Hi David,

I suggest you create a custom server control inherited from LinkButton
which takes only one parameter - the page name; then it redirects to the
correct help file according to current thread's locale. (Better yet, since
your path pattern is determined, it can also guess the page name from
Request.Path, which means your developers don't need to specify any
parameters for the custom LinkButton, simply use it where a help link is
required)

Another approach is to use URL rewriting technique, but I think it's
overkill for your purpose:

#URL Rewriting with ASP.NET - The Code Project - ASP.NET
http://www.codeproject.com/aspnet/URLRewriter.asp

Let us know what do you think of all the suggestions so far.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
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/default.aspx.
==================================================

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

Walter Wang [MSFT]

Hi David,

Your code looks great. Thank you for sharing your code.

From your another post, it seems you're experiencing rendering errors at
design-time. The reason of this is because the default designer associated
with Hyperlink control (or other descendants that are inherited from
hyperlink that don't have specified other designers) will use the Render
method to render the html for design-time. Since we don't have HttpContext
at design-time, the code throws exceptions and the designer will notify you
that it cannot render the control at design-time.

Also, I think displaying the 16x16 image at design time would be
sufficient. This can be done by creating a custom designer for your control.

By the way, you don't have to manually construct the html in Render(). From
your code, it seems you're wrapping an image tag inside a hyperlink tag,
which can be represented a hyperlink control and an image control.

I've put together following code for your reference. Note that I've written
several methods as "protected virtual" which might be useful when your user
wants to inherit from your control and provide custom implementations for
those methods.

namespace net.windward.webcontrols
{

[AspNetHostingPermission(SecurityAction.Demand, Level =
AspNetHostingPermissionLevel.Minimal),
AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
AspNetHostingPermissionLevel.Minimal),
DefaultProperty("File"),
ToolboxData("<{0}:HelpLink runat=\"server\"/>"),
Designer(typeof(HelpLinkDesigner))
]
public class HelpLink : HyperLink
{
private const string bitmap = "images/help.gif";
private const string bitmapPixels = "16";
private const string helpDir = "help/";
private const string resourceFile = "windward";
private const string resourceName = "Help_Tooltip";

public virtual string File
{
get
{
string s = (string)ViewState["File"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["File"] = value;
}
}
public virtual string Bookmark
{
get
{
string s = (string)ViewState["Bookmark"];
return (s == null) ? String.Empty : s;
}
set
{
ViewState["Bookmark"] = value;
}
}

protected override void CreateChildControls()
{
Controls.Clear();
Controls.Add(GetHelpImage());
}

protected virtual Control GetHelpImage()
{
Image img = new Image();
string text = GetHelpTooltip();
img.AlternateText = text;
img.Width = Unit.Pixel(16);
img.Height = Unit.Pixel(16);
img.Attributes.Add("title", text);
img.BorderWidth = Unit.Pixel(0);
return img;
}

public virtual string GetDesignTimeHtml()
{
StringWriter sw = new StringWriter();
HtmlTextWriter writer = new HtmlTextWriter(sw);
GetHelpImage().RenderControl(writer);
return sw.ToString();
}

protected virtual string GetHelpFile()
{
if (Context == null)
{
return "about:blank";
}

// find the correct htm file
string locale = CultureInfo.CurrentUICulture.IetfLanguageTag;
string root = Context.Request.PhysicalApplicationPath + helpDir
+ File;
string filename = root + "-" + locale + ".htm";
while ((locale.Length > 0) &&
(!System.IO.File.Exists(filename)))
{
int pos = locale.LastIndexOf('-');
if (pos > 0)
{
locale = locale.Substring(0, pos);
filename = root + "-" + locale + ".htm";
}
else
{
locale = string.Empty;
filename = root + ".htm";
}
}
// now we need the application path (for the url)
filename = File + (locale.Length > 0 ? "-" + locale : "") +
".htm";
return filename;
}

protected virtual string GetHelpTooltip()
{
return HttpContext.GetGlobalResourceObject(resourceFile,
resourceName) as string;
}

protected override void OnPreRender(EventArgs e)
{
this.Attributes.Add("title", GetHelpTooltip());
this.NavigateUrl = GetHelpFile();
this.Target = "_blank";

base.OnPreRender(e);
}

}

public class HelpLinkDesigner : ControlDesigner
{
public override string GetDesignTimeHtml()
{
HelpLink hl = (HelpLink)this.Component;
return hl.GetDesignTimeHtml();
}

public override bool AllowResize
{
get
{
return false;
}
}
}
}

Regards,
Walter Wang ([email protected], 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.
 
W

Walter Wang [MSFT]

Sure.

If you need anything else regarding this topic, please feel free to post
here.

Regards,
Walter Wang ([email protected], 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top