1
<asp:Panel runat="server" ID="pnlDocUpload">
<div class="row">
    <div class="col-md-4">
    <div class="column-pad-bottom column-pad-top">Document Title:</div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle1" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle2" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle3" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle4" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle5" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle6" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle7" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle8" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle9" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle10" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle11" CssClass="form-control"/></div>
        <div class="column-pad-bottom2"><asp:TextBox runat="server" ID="fuTitle12" CssClass="form-control"/></div>
    </div>

<H3> I tried using find controls it is always returning null </H3>



protected void btAddSection_Click(object sender, EventArgs e)
{
    string path = "C:/Users/emahou1/Desktop/testfolder";
    if (cbIsLink.Checked == true)
    {
        if (fuTitleLink.HasFile)
        {
            // it is other section has nothing to do with the 12 input tags
        }
        else
        {
            // get the link path from the text box and save it ??   
        }
    }
    else
    {
        for (int i = 0; i < Request.Files.Count; i++  )
        {
            string text = "";
            for (int t = 1; t <= 5; t++)
            {
                TextBox tb = FindControl("fuTitle" + t.ToString()) as TextBox;
                if (tb != null) text += tb.Text;
            }
            if (Request.Files[i].FileName.ToString() != "")
            {

               // here i will collect the files and the textbox values to submit them to database
            }
        }
    }
}

I have 12 input tabs that I will use to upload files to the server, I am already looping throgh the input controls to get the files, but these text boxes i want to loop through them so I can capture the text entered by the user and use that text to rename each file being uploaded ....

3
  • this are not dynamic control Commented Dec 5, 2017 at 17:55
  • 1
    when you set breakpoints, I am assuming that you are trying to get the Textbox values after doing a Button Click? edit your question, post all of the relevant code if it's on a Button_Click event as well as the Page_Load method..this could be a PostBack problem would need to see how you are Invoking the code in your for loop.. also are you familiar with doing a foreach(Control ctrl in Controls) for example.. ? Commented Dec 5, 2017 at 17:55
  • I have edited the code - take a look. Commented Dec 5, 2017 at 18:06

1 Answer 1

2

How about using FindControl inside the panel. Something like this

for (int t = 1; t <= 5; t++)
{
    TextBox tb = pnlDocUpload.FindControl("fuTitle" + t.ToString()) as TextBox;
    if (tb != null) text += tb.Text + "<br>";
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.