Link to home
Start Free TrialLog in
Avatar of SamJolly
SamJollyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Trying to remove controls dynamically from ASP.NET page.

Hi,

 I am have trouble in deleting controls from the page. I just want to remove a control dynamically from the page. The type of code I am using is :

        tb1 = DirectCast(tblTable.FindControl("Ctrl999"), TextBox)
        tblTable.Controls.Remove(tb)
        tb2 = DirectCast(tblTable.FindControl("Ctrl999"), TextBox)


It seems to find the control, but does not seem to remove the control. I can still find it after the removal ie I can reference tb2.

Thoughts?

Sam
SOLUTION
Avatar of SStory
SStory
Flag of United States of America 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 SamJolly

ASKER

Should be

  tblTable.Controls.Remove(tb1)

shouldn't it?

Absolutely....... I changed the code for my question, but included a typo ......

I have already read that article... I think the problem is that you can only remove control in the crrent context ie you have to navigate to the relevant cell and uses its remove method

ie Cells(0).RemoveAt(0)

Sam
I would really like 2 knw why u wud remove it. U dnt want 2 render it on page? If tht's the case u can set visible=false
I would really like 2 knw why u wud remove it. U dnt want 2 render it on page? If tht's the case u can set visible=false
ASKER CERTIFIED SOLUTION
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
thks