0

Can any body fix this problem plz.. it throws exception "Object reference not set to an instance of an object"

namespace MC.Master.App1
{
    public partial class EventChecker : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {



        }
       
        protected void Page_Init(object sender, EventArgs e)
        {
            
            Label FeedbackLabel = new Label();
            TextBox InputTextBox = new TextBox();
            Button SubmitButton = new Button();
           
            FeedbackLabel.ID = "FeedbackLabel";
            FeedbackLabel.Text = "Please type your name: ";
            SubmitButton.ID = "SubmitButton";
            SubmitButton.Text = "Submit";
            InputTextBox.ID = "InputTextBox";
           
            SubmitButton.Click += new System.EventHandler(SubmitButton_Click);
          
            Panel1.Controls.Add(FeedbackLabel);
            Panel1.Controls.Add(InputTextBox);
            Panel1.Controls.Add(SubmitButton);
        }
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
           
            Button SubmitButton = (Button)sender;
           
            SubmitButton.Text = "Submit again!";
           
            Label FeedbackLabel = (Label)FindControl("FeedbackLabel");
            TextBox InputTextBox = (TextBox)FindControl("InputTextBox");
           
            FeedbackLabel.Text = string.Format("Hi, {0}", InputTextBox.Text);//it throws in this line
        }
    }
}

Edited by MrBlack: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by MrBlack
0

So inputtextbox or feedbacklable or both is null ? Other controls are fine?

I would have suggested to try create controls in preinit event, however if other controls are being created successfully...

0

So inputtextbox or feedbacklable or both is null ? Other controls are fine?

I would have suggested to try create controls in preinit event, however if other controls are being created successfully...

feedbacklabel is already filled..InputTextBox user have to fill.. and i cant use preinit because im using a master page...inputtextbox pass a null value.. how to privent that..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.