Link to home
Start Free TrialLog in
Avatar of pratikshahse
pratikshahse

asked on

change the textbox name

I have a function which will delete the text in a textbox.  I have attached the code in the code window. "row" is a string value which I want to attach to the textbox name so  I can get actual textbox name. the syntax that I have is not right.  what do i need to do in order to attach a stringvalue to the textboxname to get the correct name

protected void DeleteRow( string row)
{
textbox + row .Text = "";
// row = 2
// so what i want to do is 
//textbox2.Text = "";

}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Shaun Kline
Shaun Kline
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
I know you are c# but here is the solution in vb.net

The example assumes the textbox is just on a page and not embedded in placeholders, data controls like gridviews or panels.

If in a panel it would just be

Dim tmp as textbox = Ctype(pnPanelName.findcontol("textbox" & row), textbox))
tmp.text = ""
Public Sub DeleteRow(byval row as string)

Dim tmp as textbox = Ctype(Page.findcontol("textbox" & row), textbox))
tmp.text = ""


End Sub

Open in new window

Hi pratikshahse,

U cannot assign the Text as u have done... The thing is it takes that (textbox + row) as a string and will not consider as a id of the Text Box.. u Should go with the approach suggested by Shaun_Kline...