473,378 Members | 1,142 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Turn a string into a control name

Hi All,

I have this code, which I am trying not to replicate many times in my
code-behind.

Me.img1.Visible = False
Me.img1UploadButton.Visible = True
Me.pnlImg1Uploader.Visible = True
Me.img1Cancel.Visible = True

I have mulitple controls on the page which do similar things. They are
all named in a consistant manner. e.g: img1, img2, img3...etc. I would
like to call one function to carry out the above code, but I am not
sure how to get the ID into the code. I guess something like this:
me.img+TheID+.Visible = False (Obviously that wont work, but should
give you an idea of what I'm trying to achieve)

Any help/suggestions will be appreciate.

Many Thanks.

Nov 19 '05 #1
2 1177
You can use the FindControl method as follows:

Private Sub ShowHide(ByVal index As Integer)

CType(Me.FindControl("img" & CStr(index)),
System.Web.UI.WebControls.Image).Visible = False

End Sub
The parameter for the FindControl method is a String, which is the ID of the
control you want. It sounds like you can figure everything else out from
here, if you have any questions feel free to ask. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Web Team @ Borough of Poole" <we*********@poole.gov.uk> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Hi All,

I have this code, which I am trying not to replicate many times in my
code-behind.

Me.img1.Visible = False
Me.img1UploadButton.Visible = True
Me.pnlImg1Uploader.Visible = True
Me.img1Cancel.Visible = True

I have mulitple controls on the page which do similar things. They are
all named in a consistant manner. e.g: img1, img2, img3...etc. I would
like to call one function to carry out the above code, but I am not
sure how to get the ID into the code. I guess something like this:
me.img+TheID+.Visible = False (Obviously that wont work, but should
give you an idea of what I'm trying to achieve)

Any help/suggestions will be appreciate.

Many Thanks.

Nov 19 '05 #2
Excellent - Thank you! :)

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
4
by: Bob | last post by:
Is there a way to turn off the form designer's automatic deletion of "handles <control>.<eventname>" when you delete a control? It's extremely annoying to replace one control with another of the...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
5
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE...
24
by: marcwentink | last post by:
Is there a way to turn off depreacted warnings in Visual Studio 2005, Professional Edition? I've got this VB project ported from version 2003 to 2005, I am a bit cautious to already changing the...
1
by: kal | last post by:
Hi there I am hunting for way to turn off/disable active scripting especially javascript in my webbrowser control. I don't see any property to turn off script. I found entry in registry...
1
by: robert112 | last post by:
Hi All, I have a webpage.aspx and a webusercontrol.ascx with both of them having viewstate turned off. Then in my web user control I have got some code reading the request stream: Dim str As...
4
by: BLUE | last post by:
Psion WorkAbout Pro with Windows CE .NET 4.2 Dealer gave me PowerAPIOn.exe and PowerAPIOff.exe to turn on/off tag reader, but I want to do it programmatically and do the same with WiFi and...
0
by: robert112 | last post by:
Hi all, I have a WYSIWIG editor (fckeditor) and allow the users to create dynamic html which I save and display later on in the application. The aim is to have the user be able to create...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.