ASP.NET未正确添加控件 [英] ASP.NET Not adding controls correctly

查看:64
本文介绍了ASP.NET未正确添加控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在制作这个网络应用程序的另一个问题。



很遗憾我无法理解为什么会这样做。



HTML CODE

Hello guys,

I am having an another issue with this web application I am making.

Unfortunately I can't understand why it is doing this.

HTML CODE

<nav id="mobileonly" class="clearfix"  runat="server">
    <asp:Panel ID="mobileMenuP" runat="server"></asp:Panel>
		<a href="#" id="pull">Menu</a>
	</nav>

<div class="content">
    <div class="header">
        <asp:Panel CssClass="pure-menu pure-menu-open pure-menu-fixed pure-menu-horizontal" ID="headerMenu" runat="server">

            <div style="float: right; padding-removed 9px;" class="pure-form">
                <fieldset>

                    <asp:TextBox runat="server" ID="user_email" placeholder="Email" TextMode="Email" ></asp:TextBox>
                    <asp:TextBox runat="server" ID="user_password" placeholder="Password" TextMode="Password" ></asp:TextBox>

                    <asp:Button runat="server" Text="Sign in" ID="login_button" OnClick="login_button_Click" CssClass="pure-button pure-button-primary" />
                </fieldset>
            </div>
        </asp:Panel>
        </div>
    </div>





C#CODE



C# CODE

List<HtmlGenericControl> parents = new List<HtmlGenericControl>();
//GET CONTROLS AND ADD TO parents.
//DEBUG: //Response.Write("PC: " + parents.Count);
            HtmlGenericControl[] parentsArr = parents.ToArray();
            HtmlGenericControl mainMenuMenu = new HtmlGenericControl("ul");
            for (int i = 0; i < parentsArr.Length; i++)
            {
                mainMenuMenu.Controls.Add(parentsArr[i]);
            }

            HtmlGenericControl mobileMenuMenu = mainMenuMenu;
            mobileMenuMenu.Attributes.Add("class", "clearfix");

            headerMenu.Controls.AddAt(0, mainMenuMenu);

            mobileonly.Controls.AddAt(0, mobileMenuMenu);





现在我遇到的问题是如果我评论这行代码



Now the problem I am having is that if I comment this line of code

mobileonly.Controls.AddAt(0, mobileMenuMenu);



headerMenu显示菜单没有问题。



但是当我取消评论时,headerMenu中显示的所有内容都是


    The headerMenu has no issue displaying the menu.

    But when I un-comment it, all that is displayed in the headerMenu is

      推荐答案

      我能够通过从头开始创建2个列表项来解决问题。



      我宁愿不这样做,因为它没有必要,但它没有问题。
      I was able to sort out the problem by creating 2 List Items from the start.

      I would preferred not to as it was really not necessary but it works no issue.


      这篇关于ASP.NET未正确添加控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆