Solved

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

Posted on 2010-08-17
6
658 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 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;
        }
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

11 Experts available now in Live!

Get 1:1 Help Now