質問

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