473,395 Members | 1,464 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,395 software developers and data experts.

How to reference a button

I am using VS2005 and C#

I have 10 asp buttons called Page1, Page2, Page3, ..., Page10
<asp:button id="Page1" runat="server" onClick="Page1_Click" text="1""></asp:button>
<asp:button id="Page2" runat="server" onClick="Page2_Click" text="2""></asp:button>
<asp:button id="Page3" runat="server" onClick="Page3_Click" text="3""></asp:button>
.
.
.
<asp:button id="Page10" runat="server" onClick="Page10_Click" text="10""></asp:button>

I am trying to write a for loop like the following to disable all the buttons:

for (int i=1; i <= 10, ++i)
{
Page[i].Enabled = false; //This where I need help (how can this be done?)
}

Thanks in advance,

Louis
Jul 24 '07 #1
6 1313
RedSon
5,000 Expert 4TB
I am using VS2005 and C#

I have 10 asp buttons called Page1, Page2, Page3, ..., Page10
<asp:button id="Page1" runat="server" onClick="Page1_Click" text="1""></asp:button>
<asp:button id="Page2" runat="server" onClick="Page2_Click" text="2""></asp:button>
<asp:button id="Page3" runat="server" onClick="Page3_Click" text="3""></asp:button>
.
.
.
<asp:button id="Page10" runat="server" onClick="Page10_Click" text="10""></asp:button>

I am trying to write a for loop like the following to disable all the buttons:

for (int i=1; i <= 10, ++i)
{
Page[i].Enabled = false; //This where I need help (how can this be done?)
}

Thanks in advance,

Louis
you need to do something like storing the button id in the array. Then when you access the element of the array by doing array[i] you will be getting the button id. Then you have to somehow call Enabled = false using that button id. Not sure how to do that.
Jul 24 '07 #2
you need to do something like storing the button id in the array. Then when you access the element of the array by doing array[i] you will be getting the button id. Then you have to somehow call Enabled = false using that button id. Not sure how to do that.
The later is what I am looking for, I wonder if it can be done something like:

Object.Parce("Page"+i.ToString()).Enabled = false;

What do you think, is there something to that effect?

Thanks for your response,

Louis
Jul 24 '07 #3
RedSon
5,000 Expert 4TB
The later is what I am looking for, I wonder if it can be done something like:

Object.Parce("Page"+i.ToString()).Enabled = false;

What do you think, is there something to that effect?

Thanks for your response,

Louis
Well what does Parce do? does it take a string argument? It looks like what you have would work.
Jul 24 '07 #4
Plater
7,872 Expert 4TB
All controls have a .FindControl(string) that allows you to search it's children for an object with the same name as the given string.
http://msdn2.microsoft.com/en-us/lib...ndcontrol.aspx

I believe there is an overload telling it to search it's children's children for the object too, but if not, be aware that you might have to do that.
Jul 24 '07 #5
Well what does Parce do? does it take a string argument? It looks like what you have would work.
No, Object.Parce does not work, I get an error saying that Object does not contain definition parce.
Jul 24 '07 #6
All controls have a .FindControl(string) that allows you to search it's children for an object with the same name as the given string.
http://msdn2.microsoft.com/en-us/lib...ndcontrol.aspx

I believe there is an overload telling it to search it's children's children for the object too, but if not, be aware that you might have to do that.
Thanks Plater, this works:

Expand|Select|Wrap|Line Numbers
  1. Button cntrl = null;
  2. for (int i = 1; i <= pagecount; i++) 
  3. {
  4.      cntrl = (Button)FindControl("Page" + i.ToString());
  5.      cntrl.Visible = true;
  6. }
Jul 24 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sibylle Koczian | last post by:
Still trying to learn PyQt from a book about several Python GUI toolkits, I seem to learn first what doesn't work. The following small script seems to work, but after closing the window I get the...
0
by: monkey king | last post by:
I have a given dll file(PDFCreator.dll) - probably generated by VC++. I want to use its method(PDFCreator()) in dotNet environment. It works well in WindiowsApplication, but bad in WebApplication...
0
by: Andrea Trevisan | last post by:
That's a revival of a known thing I suppose.I hope it's useful. My problem was: I want to have a DataGrid with two Template columns: first with TextBox,second with Button.I want to fire an event...
4
by: Cybertof | last post by:
Hello, What is the difference between : - adding a new reference to a namespace within the SolutionExplorer (right click, Add Reference...) - adding a new reference with the 'using' keyword in...
5
by: Sharon | last post by:
Hi to all. How do i reference a class member dynamically? Somthing like: byte i = 35; Button currentButton = this; Thanks, Sharon.
16
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project -...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
2
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back...
3
by: SAL | last post by:
I am getting the following ERROR in my WebApp on line 30: Server Error in '/TestWebApp' Application. -------------------------------------------------------------------------------- Object...
19
Frinavale
by: Frinavale | last post by:
I'm in the middle of implementing a custom Ajax enabled Server Control. At this point I need help finding the answer to an Ajax Framework question...here it goes: I have a Server Control that...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.