0

I have this peace of code which generates a dropdown menu, Unfortunately I'm running into issues because span tags are being generated at the creation of each HtmlGenericControl.

This is my code to generate the HtmlGenericControls:

    string _touid = Request.QueryString["touid"];
    string _group_array = Connections.isp_GET_VALUE("TRSTR", "", "", "");
    string _tour_array = _group_array.Replace(" ", "");

    HtmlGenericControl _ul = new HtmlGenericControl();
    _ul.InnerHtml = "<ul class=\"dropdown-menu\">";

    tour_holder.Controls.Add(_ul);

    string[] groups = _tour_array.Split(',');
    foreach (string group in groups)
    {
        string _tournoment_string = Connections.isp_GET_VALUE("TRNAM", group, "", "");

        HtmlGenericControl _li = new HtmlGenericControl();
        _li.InnerHtml = "<li><a href=\"Management.aspx?cid=" + _cid + "&touid=" + group + "\">" + _tournoment_string + "</a></li>";

        tour_holder.Controls.Add(_li);
    }
    HtmlGenericControl _ul_ = new HtmlGenericControl();
    _ul_.InnerHtml = "</ul>";
    tour_holder.Controls.Add(_ul_);      

Below is the HTML output:

<span><ul class="dropdown-menu"></span>
   <span><li><a href="Management.aspx?cid=&touid=1">FIFA World Cup Brasil 2014                      </a></li>
</span>
   <span><li><a href="Management.aspx?cid=&touid=2">FIFA U-20 World Cup New Zealand 2015              </a></li></span>
   <span><li><a href="Management.aspx?cid=&touid=3">FIFA Woman's World Cup Canada 2015                </a></li></span> 
<span></ul></span>
</div>

How can I remove the span tag?

1 Answer 1

1

A similar question has been asked here.

Try passing the HTML tag the constructor instead of using the InnerHtml property like that:

HtmlGenericControl _ul = new HtmlGenericControl("ul");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.