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

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;
        }
LVL 1
Ammar IqbalSenior IT Consultant/senior Software engineerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
StephanConnect With a Mentor Lead Software EngineerCommented:
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
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
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
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
StephanLead Software EngineerCommented:
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
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
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
 
Ammar IqbalSenior IT Consultant/senior Software engineerAuthor Commented:
Fixed it. The link is working  Thank you for the help

I needed to comment  out "css+="close""
0
All Courses

From novice to tech pro — start learning today.