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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

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 …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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