<asp:PlaceHolder runat="server" ID="ph1" ></asp:PlaceHolder> <asp:Button runat="server" ID="btnCheck" Text="Check" onclick="btnCheck_Click" />Then in the code behind I do this:
protected void [COLOR=RoyalBlue]Page[/COLOR]_[COLOR=RoyalBlue]Load[/COLOR](object sender, EventArgs e)
{
Label lbl = new Label();
lbl.Text = "<[COLOR=RoyalBlue]label [/COLOR]id='[COLOR=RoyalBlue]lbl2[/COLOR]' runat='server'>Hello2</[COLOR=RoyalBlue]label[/COLOR]>";
lbl.ID = "lbl1";
ph1.Controls.Add(lbl);
}
protected void [COLOR=RoyalBlue]btnCheck[/COLOR]_[COLOR=RoyalBlue]Click[/COLOR](object sender, EventArgs e)
{
Label tempLBL = (Label)FindControl("[COLOR=RoyalBlue]lbl2[/COLOR]");
if(tempLBL != null)
{
btnCheck.Text += "FOUND1";
}
HtmlGenericControl htmlGC= (HtmlGenericControl)FindControl("[COLOR=RoyalBlue]lbl2[/COLOR]");
if (htmlGC!= null)
{
btnCheck.Text += "FOUND2";
}
Control c = (Control)FindControl("[COLOR=RoyalBlue]lbl2[/COLOR]");
if(c != null)
{
btnCheck.Text += "C";
}
}
Problem is: I am having a hard time finding the "lbl2", which is added within the label "lbl1" in the Page_Load... None of the checks in the "btnCheck"-click goes "true", hence the "lbl2" is not found in C#, but I am able to find it in JavaScript, but that's not what I want. Also: The output of the html creates a <span> tag surrounding the two labels...
Suggestions on how I can find this label which is added like this?
Do note; simplified example... :)


Sign In
Create Account


Back to top









