Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Adding a hyperlink to a sentence of text in a bulleted list

Adding a hyperlink to a sentence of text in a bulleted list

Scheduled Pinned Locked Moved C#
helptutorialquestion
32 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Wheels012

    Good afternoon. We created a control (somecontrol.cs) which displays a dynamic bullet list. In some scenerios, one of the bullets will have a hyperlink. The problem is, the a href code renders as text. We are adding to a string List and using it as the DataSource for the bulleted list:

    private BulletedList _blConfirmText = new BulletedList();
    List<string> displayText = new List<string>();
    _confirmText.Text = CONFIRMTEXTLB;
    displayText.Add(BULLETONELB);
    displayText.Add(BULLETTWOLB);

                    if (hasUpdateAccess)                    
                        displayText.Add(BULLETTHREELBHL);                          
                    else
                        displayText.Add(BULLETTHREELB);
    

    //set the bullet style and load the bulletd list
    _blConfirmText.CssClass = "bulletItems";
    _blConfirmText.DataSource = displayText;
    _blConfirmText.DataBind();

    Any idea how to get this to render correctly? Any suggestions? Thank you, WHEELS

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #2

    What type of control is it? Is it a WinForm User control? There's no magic wand that will parse your href string and display it as a link automatically, you'll have to write your own logic to achieve this behavior. EDIT: I see that you're trying to create some sort of a Web User Control. Can you show some code where the actual rendering happens?

    W 1 Reply Last reply
    0
    • W Wheels012

      Good afternoon. We created a control (somecontrol.cs) which displays a dynamic bullet list. In some scenerios, one of the bullets will have a hyperlink. The problem is, the a href code renders as text. We are adding to a string List and using it as the DataSource for the bulleted list:

      private BulletedList _blConfirmText = new BulletedList();
      List<string> displayText = new List<string>();
      _confirmText.Text = CONFIRMTEXTLB;
      displayText.Add(BULLETONELB);
      displayText.Add(BULLETTWOLB);

                      if (hasUpdateAccess)                    
                          displayText.Add(BULLETTHREELBHL);                          
                      else
                          displayText.Add(BULLETTHREELB);
      

      //set the bullet style and load the bulletd list
      _blConfirmText.CssClass = "bulletItems";
      _blConfirmText.DataSource = displayText;
      _blConfirmText.DataBind();

      Any idea how to get this to render correctly? Any suggestions? Thank you, WHEELS

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #3

      If it's a custom control you need to make sure that you actually render an <a href=...> tag.

      1 Reply Last reply
      0
      • L Lost User

        What type of control is it? Is it a WinForm User control? There's no magic wand that will parse your href string and display it as a link automatically, you'll have to write your own logic to achieve this behavior. EDIT: I see that you're trying to create some sort of a Web User Control. Can you show some code where the actual rendering happens?

        W Offline
        W Offline
        Wheels012
        wrote on last edited by
        #4

        private const string BULLETTHREELBHL = "This is an example of the hyperlink <a href=\"/../Test/FW_DEFAULT.ASPX?Serviceid=Test&title=Test+Page>Test Page\"</a> where people click to navigate to another page.";

        B 1 Reply Last reply
        0
        • W Wheels012

          private const string BULLETTHREELBHL = "This is an example of the hyperlink <a href=\"/../Test/FW_DEFAULT.ASPX?Serviceid=Test&title=Test+Page>Test Page\"</a> where people click to navigate to another page.";

          B Offline
          B Offline
          BobJanova
          wrote on last edited by
          #5

          Your HTML is invalid (the quotes around the attribute value aren't done right).

          W 1 Reply Last reply
          0
          • B BobJanova

            Your HTML is invalid (the quotes around the attribute value aren't done right).

            W Offline
            W Offline
            Wheels012
            wrote on last edited by
            #6

            Hi Bob. What should they be? WHEELS

            B L 2 Replies Last reply
            0
            • W Wheels012

              Hi Bob. What should they be? WHEELS

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              private const string BULLETTHREELBHL = "This is an example of the hyperlink Test Page where people click to navigate to another page.";

              EDIT: If it still doesn't work, make sure that it is not Html encoded before being rendered. For example. The Text property of some controls automatically Html encode their content. So if you put html tags inside the Text property, they'll be renedered as html tags.

              1 Reply Last reply
              0
              • W Wheels012

                Hi Bob. What should they be? WHEELS

                B Offline
                B Offline
                BobJanova
                wrote on last edited by
                #8

                private const string BULLETTHREELBHL = "This is an example of the hyperlink <a href=\"/../Test/FW_DEFAULT.ASPX?Serviceid=Test&title=Test+Page\">Test Page</a> where people click to navigate to another page.";

                If you can't fix mistakes like that in HTML then why are you writing websites ...

                W 1 Reply Last reply
                0
                • B BobJanova

                  private const string BULLETTHREELBHL = "This is an example of the hyperlink <a href=\"/../Test/FW_DEFAULT.ASPX?Serviceid=Test&title=Test+Page\">Test Page</a> where people click to navigate to another page.";

                  If you can't fix mistakes like that in HTML then why are you writing websites ...

                  W Offline
                  W Offline
                  Wheels012
                  wrote on last edited by
                  #9

                  Thanks Bob and Shameel. We had done some modifications to this code and when we put it back, we must have put the syntax back incorrectly. Unfortunately after fixing the code, it still renders as text. WHEELS

                  B L 2 Replies Last reply
                  0
                  • W Wheels012

                    Thanks Bob and Shameel. We had done some modifications to this code and when we put it back, we must have put the syntax back incorrectly. Unfortunately after fixing the code, it still renders as text. WHEELS

                    B Offline
                    B Offline
                    BobJanova
                    wrote on last edited by
                    #10

                    You still haven't shown the code that actually renders this text. Do other HTML tags work correctly? If your user control simply renders the text literally into the HTML stream then it should work so I'm guessing something is wrong in that area.

                    1 Reply Last reply
                    0
                    • W Wheels012

                      Thanks Bob and Shameel. We had done some modifications to this code and when we put it back, we must have put the syntax back incorrectly. Unfortunately after fixing the code, it still renders as text. WHEELS

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #11

                      It is being Html encoded before being rendered. As I said in my previous post, certain controls automatically html encode their content before rendering. Just to test if that is the actual problem, try using a div tag (HtmlGenericControl) and set its innerText property to the desired html output.

                      W 2 Replies Last reply
                      0
                      • L Lost User

                        It is being Html encoded before being rendered. As I said in my previous post, certain controls automatically html encode their content before rendering. Just to test if that is the actual problem, try using a div tag (HtmlGenericControl) and set its innerText property to the desired html output.

                        W Offline
                        W Offline
                        Wheels012
                        wrote on last edited by
                        #12

                        Hi Shameel. The text renders correctly when set up as a label directly on the page. I believe you are correct about the encoding issue. Is there a way to decode? WHEELS

                        L 1 Reply Last reply
                        0
                        • W Wheels012

                          Hi Shameel. The text renders correctly when set up as a label directly on the page. I believe you are correct about the encoding issue. Is there a way to decode? WHEELS

                          L Offline
                          L Offline
                          Lost User
                          wrote on last edited by
                          #13

                          It depends on how you render the output. You have still not shown the code that actually renders your html output.

                          1 Reply Last reply
                          0
                          • L Lost User

                            It is being Html encoded before being rendered. As I said in my previous post, certain controls automatically html encode their content before rendering. Just to test if that is the actual problem, try using a div tag (HtmlGenericControl) and set its innerText property to the desired html output.

                            W Offline
                            W Offline
                            Wheels012
                            wrote on last edited by
                            #14

                            I had to abandon the Common control approach. I added a simple BulletedList to the .aspx file, but I am still having a very challenging time setting a hyperlink on a given word in a bullet sentence. I am starting to believe this can't be done. There are three DisplayMode options for a BulletedList: Text, HyperLink, and ImageButton, but no Text/Hyperlink combo. If you have time can you try to create one that does what I am looking for? Thanks, WHEELS

                            L 1 Reply Last reply
                            0
                            • W Wheels012

                              I had to abandon the Common control approach. I added a simple BulletedList to the .aspx file, but I am still having a very challenging time setting a hyperlink on a given word in a bullet sentence. I am starting to believe this can't be done. There are three DisplayMode options for a BulletedList: Text, HyperLink, and ImageButton, but no Text/Hyperlink combo. If you have time can you try to create one that does what I am looking for? Thanks, WHEELS

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #15

                              Bulleted list and hyperlink will definitely work. Try this:

                              • Google
                              • Bing
                              W 1 Reply Last reply
                              0
                              • L Lost User

                                Bulleted list and hyperlink will definitely work. Try this:

                                • Google
                                • Bing
                                W Offline
                                W Offline
                                Wheels012
                                wrote on last edited by
                                #16

                                Sorry Shameel. I was not entirely clear. I have done that sucessfully, but what I am looking for is the following: * This is an example of programming. Then when you click the underlined word good it takes you to http://www.codeproject.com. * is a bullet. WHEELS

                                L 1 Reply Last reply
                                0
                                • W Wheels012

                                  Sorry Shameel. I was not entirely clear. I have done that sucessfully, but what I am looking for is the following: * This is an example of programming. Then when you click the underlined word good it takes you to http://www.codeproject.com. * is a bullet. WHEELS

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #17

                                  I dont see any problem with that too:

                                  • To Access Google, click here
                                  • This takes you to Bing
                                  W 1 Reply Last reply
                                  0
                                  • L Lost User

                                    I dont see any problem with that too:

                                    • To Access Google, click here
                                    • This takes you to Bing
                                    W Offline
                                    W Offline
                                    Wheels012
                                    wrote on last edited by
                                    #18

                                    It seems to work well in the .aspx, but now I have to put it in as a dynamic variable. Is there any issue with including the a href in the string? WHEELS

                                    L 1 Reply Last reply
                                    0
                                    • W Wheels012

                                      It seems to work well in the .aspx, but now I have to put it in as a dynamic variable. Is there any issue with including the a href in the string? WHEELS

                                      L Offline
                                      L Offline
                                      Lost User
                                      wrote on last edited by
                                      #19

                                      Depends on how you put the 'href' within that string. As long as the correct html is rendered, you shouldn't have any problem. Can you care to show me your entire code that renders the output?

                                      W 1 Reply Last reply
                                      0
                                      • L Lost User

                                        Depends on how you put the 'href' within that string. As long as the correct html is rendered, you shouldn't have any problem. Can you care to show me your entire code that renders the output?

                                        W Offline
                                        W Offline
                                        Wheels012
                                        wrote on last edited by
                                        #20

                                        <ul>
                                        <li id="liBullet" />
                                        <li><a href="http://bing.com">This</a> takes you to Bing</li>
                                        </ul>

                                        C#

                                        protected System.Web.UI.WebControls.ListItem liBullet;
                                        this.liBullet.Attributes.Add(BULLETTHREELBHL);
                                        private const string BULLETTHREELBHL = "Employee earnings can be submitted through the <a href=\"/EECHG/FW_DEFAULT.ASPX?Serviceid=EECHG&title=Employee+Changes\">Employee Changes</a> service by a plan administrator with access to update employee changes.";

                                        WHEELS

                                        L 1 Reply Last reply
                                        0
                                        • W Wheels012

                                          <ul>
                                          <li id="liBullet" />
                                          <li><a href="http://bing.com">This</a> takes you to Bing</li>
                                          </ul>

                                          C#

                                          protected System.Web.UI.WebControls.ListItem liBullet;
                                          this.liBullet.Attributes.Add(BULLETTHREELBHL);
                                          private const string BULLETTHREELBHL = "Employee earnings can be submitted through the <a href=\"/EECHG/FW_DEFAULT.ASPX?Serviceid=EECHG&title=Employee+Changes\">Employee Changes</a> service by a plan administrator with access to update employee changes.";

                                          WHEELS

                                          L Offline
                                          L Offline
                                          Lost User
                                          wrote on last edited by
                                          #21

                                          Attributes.Add() method takes 2 arguments, this code shouldn't compile at all. You should ideally be using ListItem.Text property to render your output.

                                          W 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups