Adding a hyperlink to a sentence of text in a bulleted list
-
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
-
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?
<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
-
<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
-
Attributes.Add()
method takes 2 arguments, this code shouldn't compile at all. You should ideally be usingListItem.Text
property to render your output. -
When I dynamically populate the .text property, I get an Object reference not set to an instance of an object error. System.NullReferenceException.
-
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> -
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> -
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.
-
You should have told this earlier, try this:
System.Web.UI.HtmlControls.HtmlGenericControl liBullet = new System.Web.UI.HtmlControls.HtmlGenericControl("li");
-
What property do I use in liBullet? There doesn't seem to be a text property, and innertext didn't work.
-
Try other alternatives suggested in this post: http://stackoverflow.com/questions/6142393/custom-control-asp-net-unordered-list-with-link-inside-lis-control[^]