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.
  • 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
                      • L Lost User

                        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 Offline
                        W Offline
                        Wheels012
                        wrote on last edited by
                        #22

                        When I dynamically populate the .text property, I get an Object reference not set to an instance of an object error. System.NullReferenceException.

                        L 1 Reply Last reply
                        0
                        • W Wheels012

                          When I dynamically populate the .text property, I get an Object reference not set to an instance of an object error. System.NullReferenceException.

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

                          Can you show the code here?

                          W 1 Reply Last reply
                          0
                          • L Lost User

                            Can you show the code here?

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

                            protected System.Web.UI.WebControls.ListItem liBullets;

                            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.";

                            this.liBullets.Text = BULLETTHREELBHL;

                            <ul>
                            <li id="liBullets" />
                            <li>To Access Google, click <a href="http://google.com">here</a></li>
                            <li><a href="http://bing.com">This</a> takes you to Bing</li>
                            </ul>

                            L 1 Reply Last reply
                            0
                            • W Wheels012

                              protected System.Web.UI.WebControls.ListItem liBullets;

                              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.";

                              this.liBullets.Text = BULLETTHREELBHL;

                              <ul>
                              <li id="liBullets" />
                              <li>To Access Google, click <a href="http://google.com">here</a></li>
                              <li><a href="http://bing.com">This</a> takes you to Bing</li>
                              </ul>

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

                              so, does this throw some exception or it renders the text with the tags ?

                              W 1 Reply Last reply
                              0
                              • L Lost User

                                so, does this throw some exception or it renders the text with the tags ?

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

                                I have to declare the* id, and protected System.Web.UI.WebControls.ListItem liBullets; is incorrect. That appears to be reserved for drop-down or list boxes. I'm not sure what type the

                                • is to be decalred as.
                                L 1 Reply Last reply
                                0
                                • W Wheels012

                                  I have to declare the* id, and protected System.Web.UI.WebControls.ListItem liBullets; is incorrect. That appears to be reserved for drop-down or list boxes. I'm not sure what type the

                                  • is to be decalred as.
                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #27

                                  You should have told this earlier, try this:

                                  System.Web.UI.HtmlControls.HtmlGenericControl liBullet = new System.Web.UI.HtmlControls.HtmlGenericControl("li");

                                  W 1 Reply Last reply
                                  0
                                  • L Lost User

                                    You should have told this earlier, try this:

                                    System.Web.UI.HtmlControls.HtmlGenericControl liBullet = new System.Web.UI.HtmlControls.HtmlGenericControl("li");

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

                                    What property do I use in liBullet? There doesn't seem to be a text property, and innertext didn't work.

                                    L 1 Reply Last reply
                                    0
                                    • W Wheels012

                                      What property do I use in liBullet? There doesn't seem to be a text property, and innertext didn't work.

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

                                      innerText should work, what do you mean by didn't work? you mean nothing was rendered?

                                      W 1 Reply Last reply
                                      0
                                      • L Lost User

                                        innerText should work, what do you mean by didn't work? you mean nothing was rendered?

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

                                        The bullet rendered, but nothing else.

                                        L 1 Reply Last reply
                                        0
                                        • W Wheels012

                                          The bullet rendered, but nothing else.

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

                                          Try other alternatives suggested in this post: http://stackoverflow.com/questions/6142393/custom-control-asp-net-unordered-list-with-link-inside-lis-control[^]

                                          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