Link to home
Start Free TrialLog in
Avatar of Webboy2008
Webboy2008

asked on

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

Avatar of kswathi
kswathi
Flag of India image

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.


ASKER CERTIFIED SOLUTION
Avatar of guramrit
guramrit
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Webboy2008
Webboy2008

ASKER

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