• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

asp.net c# ascx

Please view my attached codes...how can i capture the value from the attached code
and save into the database?

protected void BtnSubmit_Click(object sender, EventArgs e)
    {
      //How can I capture the textbox value?
    }

I tried the following codes and it does not work...


TextBox tb = (TextBox)this.Page.FindControl("TxtItem_1");
            if (tb != null)
                Label2.Text = tb.Text;
            else
            {
                Label2.Text = "Nothing";
            }
protected void DdlTotalItem_SelectedIndexChanged(object sender, EventArgs e)
    {
        int TotalItemCount = int.Parse(DdlTotalItem.SelectedValue);
        if (TotalItemCount >= 1)
        {
            // DdlTotalItem.Visible = true;
            MasterListItem.Visible = true;
            MasterListItemTable.Visible = true;
            for (int i = 0; i < TotalItemCount; i++)
            {
                Obout.Interface.OboutTextBox ItemTextBox = new Obout.Interface.OboutTextBox();
                ItemTextBox.ID = "TxtItem_" + i;
                ItemTextBox.Width = 150;

              

                DivItemCode.Controls.Add(ItemTextBox);
                
            }
        }
        else
        {
            MasterListItem.Visible = false;
            MasterListItemTable.Visible = false;
        }
    }

Open in new window

0
Webboy2008
Asked:
Webboy2008
1 Solution
 
kswathiCommented:
You need to find the obout text box i.e.
 Obout.Interface.OboutTextBox tb  =  (Obout.Interface.OboutTextBox)this.Page.FindControl("TxtItem_1");

hope it helps.


0
 
guramritCommented:
You need to use following code

DivItemCode.FindControl("TxtItem_1");

instead of

this.Page.FindControl("TxtItem_1");

eg.
Obout.Interface.OboutTextBox tb  =  (Obout.Interface.OboutTextBox)DivItemCode.FindControl("TxtItem_1");
0
 
Webboy2008Author Commented:
To both....Your codes won't work because I have a for loop to generate the id for each text box.

how can add a code like FindControl("Txtitem_i")?

Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now