Reputation: 3
I have two user controls created in my UC folder. I need to load them in my page depending on the scenario based in the CS file. In my CS file I have
protected override string GetMessage()
{
if (previousAttempts == 0)
{
message = GetResourceString("Intro");
}
else if (previousAttempts == 1)
{
message = GetResourceString("Intro2");
//LOAD USER CONTROL ONE HERE
}
else
{
message = GetResourceString("Pass");
//LOAD USER CONTROL TWO HERE
}
return message;
}
I have my user controls registered in the default page as follows
<%@ Register Src="~/UserControls/AnswerUC1.ascx" TagPrefix="UC1" TagName="ANSWERUC1" %>
<%@ Register Src="~/UserControls/AnswerUC2.ascx" TagPrefix="UC2" TagName="AnswerUC2" %>
How Can i call this and make it load thru my CS file?
Upvotes: 0
Views: 1093
Reputation: 558
You have to use this controls in your .aspx file. Your control have to run as Server! and give them unique id. Now, you can access them in your code-behind through these unique ids!
Upvotes: 0
Reputation: 1150
Assuming that you are going to load this into a place holder control (placeHolder1),
placeHolder1.Controls.Add((ANSWERUC1)LoadControl("~/UserControls/AnswerUC1.ascx"));
There is an MSDN article that explains this in detail with samples.
Upvotes: 1