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

  • Home
  • SEARCH
  • 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 7799997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:29:23+00:00 2026-06-02T00:29:23+00:00

I have a method that creates textboxes depending on the number of parameters values

  • 0

I have a method that creates textboxes depending on the number of parameters values that the user has to enter.And its working fine. The problem is that when the user clicks Ok i want to take the value that the user entered in these textboxes and replace them in a string. When am searching these textboxes to get the text value from them am not finding them. How do i get these values to continue my project? the code is:

 protected void btnPreview_Click(object sender, EventArgs e)
    {
        lbHeader.Text = "Template Designer";
        divQueryBuilder.Visible = false;
        divTemplateDesigner.Visible = false;
        divFloating.Visible = true;

        if (txtQuery.Text.Contains("WHERE") || txtQuery.Text.Contains("where")||txtQuery.Text.Contains("Where"))
        {
            string[] splitter=new string[10];
            splitter[0]="Where";
            splitter[1]="WHERE";
            splitter[2]="where";
            splitter[3]="AND";
            splitter[4] = "and";
            splitter[5] = "And";
            string[] condition=txtQuery.Text.Split(splitter, StringSplitOptions.None);
            int numberOfParameters = condition.Length - 1;
            string[] Condition1 =null;
            Label[] newLabel = new Label[10];
            TextBox[] txtBox = new TextBox[10];
            for (int i = 0; i < numberOfParameters; i++)
            {
                string lbValue="lbValue";
                string lbID=lbValue+i;
                string txtValue = "txtValue";
                string txtID = txtValue + i;
                HtmlGenericControl genericControl = new HtmlGenericControl("br/");
                Condition1 = condition[i + 1].Split('[', ']');
                newLabel[i] = new Label();
                txtBox[i] = new TextBox();
                newLabel[i].ID=lbID;
                newLabel[i].Text = Condition1[1];
                txtBox[i].ID = txtID;

                td2.Controls.Add(newLabel[i]);
                td2.Controls.Add(genericControl);
                td2.Controls.Add(txtBox[i]);
                td2.Controls.Add(genericControl);
                txtBox[i].EnableViewState = true;
            }
        }
    }

 private bool ControlExistence(string lbID)
    {
        try
        {
            td2.FindControl(lbID);
            return true;
        }
        catch(Exception ex)
        {
            return false;
        }
    }

    protected void btnOk_Click(object sender, EventArgs e)
    {
       // GetTextBoxValues();
        string[] splitter1 = new string[10];
        splitter1[0] = "Where";
        splitter1[1] = "WHERE";
        splitter1[2] = "where";
        splitter1[3] = "AND";
        splitter1[4] = "and";
        splitter1[5] = "And";
        string[] condition = txtQuery.Text.Split(splitter1, StringSplitOptions.None);
        int numberOfParameters = condition.Length - 1;
        string[] splitter = new string[4];
        splitter[0] = "[";
        splitter[1] = "]";
        splitter[2] = "'";

        string[] queryBoxValue = txtQuery.Text.Split(splitter,StringSplitOptions.RemoveEmptyEntries);
        StringBuilder query = new StringBuilder();
        TextBox txtBox = new TextBox();

        for (int i = 0; i < queryBoxValue.Length; i++)
        {
            if (!queryBoxValue[i].Contains("?"))
            {
                query.Append(queryBoxValue[i]);
                query.Append(" ");
            }
            else
            {
                for (int counter1 = 0; counter1 < numberOfParameters; counter1++)
                {
                    string txtValue = "txtValue";
                    string txtID = txtValue + counter1;
                    if (ControlExistence(txtID))
                    {
                        TextBox box = (TextBox)td2.FindControl(txtID);
                        string b = box.Text;
                        //txtBox.ID = txtID;
                    }
                    txtBox.Text = "'" + txtBox.Text + "'";
                    queryBoxValue[i] = queryBoxValue[i].Replace(queryBoxValue[i], txtBox.Text);
                    query.Append(queryBoxValue[i]);
                }

            }
        }
        string fireQuery = query.ToString();
        adp = new SqlDataAdapter(fireQuery, conn);
        tab = new DataTable();
        adp.Fill(tab);
        if (tab.Rows.Count > 0)
        {
            string[] tempString = txtTemplate.Text.Split(' ');
            for (int j = 0; j < tempString.Length; j++)
            {
                if (tempString[j].StartsWith("["))
                {
                    txtPreview.Text = txtTemplate.Text.Replace(tempString[j], tab.Rows[0][0].ToString());
                }
            }
        }
        divFloating.Visible = false;
        divQueryBuilder.Visible = false;
        divTemplateDesigner.Visible = true;
    }

Please help. This has become a blocker for me.

  • 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-02T00:29:25+00:00Added an answer on June 2, 2026 at 12:29 am

    Have a list of the added controls and use it when needed.

            for (int i = 0; i < numberOfParameters; i++)
            {
                // ...
    
                td2.Controls.Add(newLabel[i]);
                td2.Controls.Add(genericControl);
                td2.Controls.Add(txtBox[i]);
                td2.Controls.Add(genericControl);
    
                addedTextBoxes.Add(txtBox[i]);
    
                // ...
            }
    

    And then from another part of your code:

    var values = addedTextBoxes.Select(tb => tb.Text).ToList();
    
    foreach (var txtBox in addedTextBoxes)
    {
        // ...
    }
    

    etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method that creates a local textfield and pops up the keyboard
I have a method that contains the following (Java) code: doSomeThings(); doSomeOtherThings(); doSomeThings() creates
I have a method CreateAccount(...) that I want to unit test. Basically it creates
I have a unit test that creates a mock calls my method to be
Currently I have created a ABCFactory class that has a single method creating ABC
So I have an extension method for the Html.CheckBoxFor() method that enables the user
I have a project I am currently working on that has multiple validators and
I have created a method that should ideally take a single Account object and
Hi I want to create a WCF service that have login method, which is
I have created a new method in one of the project's controllers that it

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.