how to get the hyperlink working  in C sharp string variable?

Posted on 2010-08-17
Last Modified: 2012-06-27
I need to display a following message using dmessages severity level. The message is displayed but the hyperlink in that message is not working properly. Instead of going to the desired message, it simply refresges the page, and disappears the message.
my code script is given below

DisplayMessage method is being called  over here
string msg=DisplayMessage();
dMessages.Controls.Add(addMessage(msg, 2));////

///////////////Body of Display Message
private string DisplayMessage()
            HyperLink hlink = new HyperLink();
            hlink.NavigateUrl = "~/Admin/CreateProject.aspx";
            hlink.Text = "Create Project";
            string message="You have not a created a project yet. Please go to the following link to do  '" + hlink.Text + "'";

            return message;
Question by:Ammar Iqbal
  • 4
  • 2
LVL 16

Accepted Solution

Stephan earned 500 total points
ID: 33453138
The only thing you do is setting the text value of the hyperlink to the message, not the control.

I recommend you to not use the HyperLink, but to use a standard html a tag like this:

private string DisplayMessage()
            string message= String.Format("You have not a created a project yet. Please go to the following link to do  <a href=\"{0}Admin/CreateProject.aspx\">Create Project</a>", System.Web.HttpContext.Current.Request.ApplicationPath);

            return message;

Author Comment

by:Ammar Iqbal
ID: 33453161
But still I have the same problem, when ever I click  create Project hyperlink  within the message, the message disappears ,it is ont going to the desired page

Author Comment

by:Ammar Iqbal
ID: 33453194
If I display this text thorugh  a normal text box property, the hypeerlink works fine, but the problem is that I am using  "dMessages" functionality. I displaying the message using a level of sevirty 2.
The message is displayed in red., but on clicking the link within the message, the message disaapears and then nothing.
I want to go to the create Project page once the hyperlink link within the message is displayed
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

LVL 16

Expert Comment

ID: 33453264
So you're saying the following:
- the message is displaying but the link does not work
- the messages dissapears after the click event

How do you display the message?

Author Comment

by:Ammar Iqbal
ID: 33453274
i am displaying the <div> section of dmessages in the  file as
                    string msg=DisplayMessage();
                    dMessages.Controls.Add(addMessage(msg, 1));

the body of add message method  is this:
 private Label addMessage(string message, int severity)
            Label label = new Label();
            string css = "message";
            if (severity == 0) css += " success";
            else if (severity == 1) css += " warning";
            else if (severity == 2) css += " error";
            else css += " information";
            css += " close";
            label.CssClass = css;
            label.Text = message;
            return label;

Author Comment

by:Ammar Iqbal
ID: 33453348
Fixed it. The link is working  Thank you for the help

I needed to comment  out "css+="close""

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now