I am trying to dynamically create controls and give them properties during run time.
I have put my code inside the Page_Init event, when I run my website I can see m
The FindControl
is failing because it can't find the control and causing a null reference.
Just reference it directly using FeedbackLabel
as you already have it in your class. Just move the scope outside of your 'Init' method.
private Label feedbackLabel = new Label();
private TextBox inputTextBox = new TextBox();
private Button submitButton = new Button();
public void Page_Init(EventArgs e)
{
feedbackLabel.ID = "FeedbackLabel";
}
protected void SubmitButton_Click(object sender, EventArgs e)
{
feedbackLabel.Text =...;
}