문제

This is something I do all the time...i'm sure it's just early morning syndrome but I can't see what's wrong here.

The same object is being set in different ways but the second time I can't see to reference it.

Markup:

<asp:Repeater runat="server" id="rptSecondTab" OnItemDataBound="rptSecondTab_ItemDataBound">
    <ItemTemplate>
        <div id="divIcon" ClientIDMode="Static" runat="server" class="tab-pane overflow-auto">
            <asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
        </div>
    </ItemTemplate>
</asp:Repeater>

Code:

((HtmlGenericControl)e.Item.FindControl("divIcon")).ID = NavURL;

if (secondFirstRun)
{
  ((HtmlGenericControl)e.Item.FindControl("divIcon")).Attributes.Add("class", "active tab-pane overflow-auto");
}

Setting the ID works fine but setting the active attribute falls over with:

Object reference not set to an instance of an object.

On the attribute adding line

도움이 되었습니까?

해결책

You are changing the id of control, which probably is not required, and lster accessing the control with the old id. you would use NavURL instead of divIcon. You better store the divIcon in some object and later use it.

HtmlGenericControl htmlGenericControl = ((HtmlGenericControl)e.Item.FindControl("divIcon")).ID = NavURL;

if (secondFirstRun)
{
      htmlGenericControl .Attributes.Add("class", "active tab-pane overflow-auto");
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top