[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

change the textbox name

Posted on 2010-03-29
3
Medium Priority
?
289 Views
Last Modified: 2012-05-09
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

0
Comment
Question by:pratikshahse
3 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 29012958
You can use the FindControl method to find controls by their name. As a example:

((TextBox)Page.FindControl("myTextBox" + row)).Text = string.empty;

In this example, Page is the container for "myTextBox1".

If your textbox is in a gridview, you need to use the gridviewrow that contains the textbox.
0
 
LVL 8

Expert Comment

by:Lotok
ID: 29018512
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

0
 
LVL 15

Expert Comment

by:rajeeshmca
ID: 29056592
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...
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question