Click here to Skip to main content
Licence CPOL
First Posted 13 Jun 2009
Views 13,981
Downloads 87
Bookmarked 32 times

ASP.NET PartialHyperLink Control

By Uwe Keim | 16 Jun 2009 | Unedited contribution
Introducing a small user control to simplify localization of literal text with contained hyperlinks

1

2
1 vote, 9.1%
3
2 votes, 18.2%
4
8 votes, 72.7%
5
4.84/5 - 11 votes
1 removed
μ 4.52, σa 1.18 [?]

Introduction

Recently I has the need to localize some .ASPX files. I did that the standard way by using the "Generate local resources" tool bar button in the design view of an .ASPX file inside Visual Studio .NET 2008. 

Among others, I used the ASP.NET HyperLink control for hyperlinks and the ASP.NET Localize control for literal text.

What bothered me was that I often had a sentence with a hyperlink inside. E.g. "To get further information, please visit the support pages on our web site".

In the above example, I would have to split the sentence into two Localize controls and one HyperLink control. Too much effort for a lazy developer. In addition, the "split position" could vary among the different languages and the hyperlink also could be different in each language.

Introducing the PartialHyperLink Control

To make the described scenario more easy to handle, I wrote myself a light-weight control named "PartialHyperLink".

The control consists of one single .CS file that you can drop into your (web) project and use immediately.

It contains the following features:

  • Mimics the most common features of a standard HyperLink control
  • Has a NavigateUrl property that is localizable
  • Has a Text property that can include a start and an end placeholder to indicate where you want the clickable hyperlink

Using the Code

To use the control, simply put the "PartialHyperLink.cs" file into the "App_Code" folder of your web project.

Next, register the control on each .ASPX page you want to use it, by writing the following line at the top of the page:

<%@ Register Namespace="App_Code" TagPrefix="zeta" %>

Last, create an instance of the control by writing code similar to the following one:

<zeta:PartialHyperLink 
    runat="server" 
    ID="MyHyperLink" 
    Text="This text that {0}includes a hyperlink{1} is inside a single control"
    NavigateUrl="http://www.zeta-test.com" 
    meta:resourcekey="MyHyperLinkResource1" />

Use the placeholders "{0}" and "{1}" inside the Text property to mark the start and end of the clickable hyperlink.

That's all!

I've included a small example project to demonstrate how to use the control. If you open and run the project's solution, try switching the languages of your browser to see the different texts and hyperlinks that are loaded from the resources. I've included the languages English and German to give you an idea.

Conclusion

In this article, I have shown you a small user control that tries to simplify the task of translating literal texts with hyperlinks.

Maybe I am on a totally wrong path and there is already a built-in way of doing things that I implemented in my control. If yes, please tell me, I'd love to know!

In addition, if you have any questions, comments, bug reports or suggestions, please write them below in the comments section of this article. Thank you!

History

  • 2009-06-12
    • First published on The Code Project

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Uwe Keim

Software Developer (Senior)
Zeta Software GmbH
Germany Germany

Member
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He is also teached programming to students at the local university.
 
In his free time, he does climbing, running and mountain biking. You can watch him most of the day (and probably night) programming.
 
Some cool, free software from us:
 
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 PinmemberDoug D in NH12:17 22 Jun '11  
GeneralAwesome Pinmemberjasonp128:37 29 Dec '09  
GeneralRe: Awesome PinsitebuilderUwe Keim9:20 29 Dec '09  
GeneralNice idea, two small problems PinmemberRichard Deeming4:26 16 Jun '09  
GeneralRe: Nice idea, two small problems PinsitebuilderUwe Keim4:35 16 Jun '09  
GeneralRe: Nice idea, two small problems PinsitebuilderUwe Keim5:20 16 Jun '09  
I have just updated the article with your suggested corrections.
 
Thank you very much!
 
My personal 24/7 webcam
Zeta Test - Intuitive, competitive Test Management environment for Test Plans and Test Cases. Download now!
Zeta Producer Desktop CMS - Intuitive, very easy to use. Download now!

GeneralGreat Idea PinmemberPeter Lange10:52 13 Jun '09  
GeneralRe: Great Idea PinsitebuilderUwe Keim10:54 13 Jun '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 16 Jun 2009
Article Copyright 2009 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid