Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2010-08-17
6
Medium Priority
?
669 Views
Last Modified: 2012-06-27
Hi,
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;
        }
0
Comment
Question by:Ammar Iqbal
  • 4
  • 2
6 Comments
 
LVL 16

Accepted Solution

by:
Stephan earned 2000 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;
        }
0
 
LVL 1

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
0
 
LVL 1

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
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 16

Expert Comment

by:Stephan
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?
0
 
LVL 1

Author Comment

by:Ammar Iqbal
ID: 33453274
i am displaying the <div> section of dmessages in the Deafult.aspx.cx  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;
        }
0
 
LVL 1

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""
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Screencast - Getting to Know the Pipeline
Suggested Courses

824 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