NibblyPig
NibblyPig

Reputation: 52942

The TargetControlID is not valid / adding a control to a form in the asp.net code

I am trying to add a control that I define in C# to my asp code, by doing this in my code:

<% this.Controls.Add(blah.GetControl()); %>

but I get the error: The TargetControlID of 'a8f08c40d0fab104ca20b1460ee1cbdd1e121' is not valid. The value cannot be null or empty.

Thats the controls GUID that I randomly generate in the get method.

Any explanation as to why I am getting it? Is what I am doing even allowed - putting that code above into my aspx file?

Edit: Additional code for the new ID problem:

.
.
    <div id="divDetailsContent" style="width:100%">
.
.
<% this.Controls.Add(blah.GetControl("divDetailsContent")); %>
.
.
public static blah GetControl(n)
{
.
.
blah.TargetID = n;
.
.
}

Upvotes: 0

Views: 4757

Answers (1)

olle
olle

Reputation: 4595

in blah.GetControl() you are instantiating a control with ID 'a8f08c40d0fab104ca20b1460ee1cbdd1e121'. This control is of a type that has a property TargetControlID like for instance the Accordion control. So you will need to set this TargetControlID to a valid id of a control as well in the GetControl. So set both ID and TargetontrolID.

update: you can get the id with the ClientID property. This contains the full ID as it's rendered in the HTML.

Upvotes: 1

Related Questions