Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9034017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:22:39+00:00 2026-06-16T08:22:39+00:00

Im creating a survey page, this page pulls from the database to display questions

  • 0

Im creating a survey page, this page pulls from the database to display questions based on their type, For each type I have created a user control. At Page_Load, I place the User Control in a placeholder like this:- (QNO is a session i set to 0 on the previous page, just to start the question order)

protected void Page_Load(object sender, EventArgs e)
        {

            SqlConnection Connection = DatabaseConnection.GetSurveySystemConnection();

            string sqlquery = "SELECT Q.[ID], Q.[Question_Order], Q.[Question], QT.[Type_Desc] FROM [Questions] Q Inner join Question_Type QT On Q.Type_ID= QT.ID Where Q.[Survey_ID] =" + Session["Survey_ID"] + "Order by Question_Order";

            SqlCommand cmd = new SqlCommand(sqlquery, Connection);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataTable DT = new DataTable();
            da.Fill(DT);

            if (DT != null)
            {
                Session["Count"] = DT.Rows.Count;
                QuestionLabel.Text = String.Format("{0}.{1}", DT.Rows[Convert.ToInt32(Session["QNO"])]["Question_Order"].ToString(), DT.Rows[Convert.ToInt32(Session["QNO"])]["Question"].ToString());
                Session["Question_ID"] = DT.Rows[Convert.ToInt32(Session["QNO"])]["ID"].ToString();

                if (DT.Rows[Convert.ToInt32(Session["QNO"])]["Type_Desc"].ToString() == "Multiple Choice")
                {
                    Control uc = Page.LoadControl("UserControls/MultipleChoice.ascx");
                    PlaceHolder2.Controls.Add(uc);
                }
                else if (DT.Rows[Convert.ToInt32(Session["QNO"])]["Type_Desc"].ToString() == "Single Choice")
                {
                    Control uc = Page.LoadControl("UserControls/SingleChoice.ascx");
                    PlaceHolder2.Controls.Add(uc);
                }
                else if (DT.Rows[Convert.ToInt32(Session["QNO"])]["Type_Desc"].ToString() == "Yes/No")
                {
                    Control uc = Page.LoadControl("UserControls/YesOrNo.ascx");
                    PlaceHolder2.Controls.Add(uc);
                }
                else if (DT.Rows[Convert.ToInt32(Session["QNO"])]["Type_Desc"].ToString() == "Agree/Disagree")
                {
                    Control uc = Page.LoadControl("UserControls/AgreeDisagree");
                    PlaceHolder2.Controls.Add(uc);
                }
                else if (DT.Rows[Convert.ToInt32(Session["QNO"])]["Type_Desc"].ToString() == "Rating")
                {
                    Control uc = Page.LoadControl("UserControls/Rating.ascx");
                    PlaceHolder2.Controls.Add(uc);
                }
                else if (DT.Rows[Convert.ToInt32(Session["QNO"])]["Type_Desc"].ToString() == "Open Ended")
                {
                    Control uc = Page.LoadControl("UserControls/OpenEnded.ascx");
                    PlaceHolder2.Controls.Add(uc);
                }
            }
        }

Now, lets say for the type “Open Ended”, it displays a textbox in the usercontrol, I want to access this textbox and retrieve the text inside it and put it in another textbox at the push of a button, I created a static textbox on the page and called it ViewTextBox.
This is what i tried:-

 protected void Button1_Click(object sender, EventArgs e)
            {
    TextBox t = Controls[0].Controls[3].Controls[11].Controls[5].Controls[0].Controls[0] as TextBox;
    ViewTextBox.Text = t.Text; //"Object reference not set to an instance of an object."
            }

Any Ideas? I dug my way through the controls on the page to find the textbox in the usercontrol :-

Response.Write(Controls[0].Controls[3].Controls[11].Controls[5].Controls[0].Controls[0].ID);

And the ID comes up as the textbox im looking for. The textbox in the usercontrol is called “OpenEndedTextBox”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:22:41+00:00Added an answer on June 16, 2026 at 8:22 am

    Instead of digging like that, I would suggest creating a Method or Property in your user control to get that text from your User Control like this

    public string GetAnsweredText()
    {
       return this.AnswerTextBox.Text;
    }
    

    and call this Method in your button’s click event in your page containing that user control like this

    protected void Button1_Click(object sender, EventArgs e)
    {
       UC_SurveyControl control = this.Controls[0] as UC_SurveyControl;
       if (control != null)
           string answer = control.GetAnsweredText();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a survey with 10 questions. All questions have 5 possible answers with
I am creating a survey form that needs to have each question and set
I am creating a survey page that has a list of questions and answers
I am creating a survey. There are 31 possible questions, I would like each
I am creating a survey app for android. If I have 50 questions do
I am creating a custom Survey package which has questions module , answers module
I am creating a survey application so I created a surveys controller that behaves
I'm working on creating an online guide. It will survey users, and based on
I am creating a question type for a survey. I am using the below
Creating a mini-database with access, i came across this problem: For the background, i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.