I'd like to be able to make a web controls such as a textbox
either visible or not-visible by using the name of the textbox
in a string and using that string in some command.
sort of like:
string str1; 8 1250
Page.FindControl("mycontrolname")
--
2005 Microsoft MVP C#
Robbe Morris http://www.robbemorris.com http://www.masterado.net/home/listings.aspx
"Robert Megee" <rm*****@comcast.net> wrote in message
news:u0********************************@4ax.com... I'd like to be able to make a web controls such as a textbox either visible or not-visible by using the name of the textbox in a string and using that string in some command. sort of like: string str1; . . . str1 = "textbox1"; . . . @str1.Visible = true;
where the @ would mean substitue the value of the string in this context.
I've seen a reference to pointers such as are used in C, but I can't find any examples. Perhaps this is a way to do this.
Thanks,
Robert
Robert,
It's not actually clear to me what you want, but I'll answer anyway :-)
This (untested!) function enumerates all controls in a container and if the
control name matches
void SetVisible (ControlCollection controls, string controlName, bool
isVisible)
{
foreach (Control control in controls)
{
if (String.Compare(control.Name, controlName, true)) == 0)
{
control.Visible = isVisible;
return;
}
}
From the form class you can use it like this:
SetVisible(this, "txtName", true);
You might want to call this function recursively if you use control
containers like Panel.
HTH,
Alexander
"Robert Megee" <rm*****@comcast.net> wrote in message
news:u0********************************@4ax.com... I'd like to be able to make a web controls such as a textbox either visible or not-visible by using the name of the textbox in a string and using that string in some command. sort of like: string str1; . . . str1 = "textbox1"; . . . @str1.Visible = true;
where the @ would mean substitue the value of the string in this context.
I've seen a reference to pointers such as are used in C, but I can't find any examples. Perhaps this is a way to do this.
Thanks,
Robert
"Robert Megee" <rm*****@comcast.net> wrote in message
news:u0********************************@4ax.com... I'd like to be able to make a web controls such as a textbox either visible or not-visible by using the name of the textbox in a string and using that string in some command. sort of like: string str1; . . . str1 = "textbox1"; . . . @str1.Visible = true;
where the @ would mean substitue the value of the string in this context.
I've seen a reference to pointers such as are used in C, but I can't find any examples. Perhaps this is a way to do this.
Thanks,
Robert
string str1;
str1 = "textbox1";
Control myControl1 = FindControl(str1);
if(myControl1!=null)
{
myControl1.Visible = true;
}
Since there are several controls that I want to toggle, this
may prove quite useful. I'll see what I can do with it.
thanks!
Robert
On Fri, 11 Mar 2005 09:21:54 +0700, "Alexander Shirshov"
<al*******@omnitalented.com> wrote: Robert,
It's not actually clear to me what you want, but I'll answer anyway :-)
This (untested!) function enumerates all controls in a container and if the control name matches
void SetVisible (ControlCollection controls, string controlName, bool isVisible) { foreach (Control control in controls) { if (String.Compare(control.Name, controlName, true)) == 0) { control.Visible = isVisible; return; } }
From the form class you can use it like this:
SetVisible(this, "txtName", true);
You might want to call this function recursively if you use control containers like Panel.
HTH, Alexander
"Robert Megee" <rm*****@comcast.net> wrote in message news:u0********************************@4ax.com.. . I'd like to be able to make a web controls such as a textbox either visible or not-visible by using the name of the textbox in a string and using that string in some command. sort of like: string str1; . . . str1 = "textbox1"; . . . @str1.Visible = true;
where the @ would mean substitue the value of the string in this context.
I've seen a reference to pointers such as are used in C, but I can't find any examples. Perhaps this is a way to do this.
Thanks,
Robert
I'll check it out. Thanks.
Robert
On Thu, 10 Mar 2005 21:18:17 -0500, "Robbe Morris [C# MVP]"
<in**@turnkeytools.com> wrote: Page.FindControl("mycontrolname") string str1; str1 = "textbox1"; Control myControl1 = FindControl(str1); if(myControl1!=null) { myControl1.Visible = true; }
Sweet! This will be perfect! many thanks.
Robert
Ask for a WebForms solution and receive WinForms one for free!
"Robert Megee" <rm*****@comcast.net> wrote in message
news:19********************************@4ax.com... Since there are several controls that I want to toggle, this may prove quite useful. I'll see what I can do with it. thanks!
Robert On Fri, 11 Mar 2005 09:21:54 +0700, "Alexander Shirshov" <al*******@omnitalented.com> wrote:
Robert,
It's not actually clear to me what you want, but I'll answer anyway :-)
This (untested!) function enumerates all controls in a container and if the control name matches
void SetVisible (ControlCollection controls, string controlName, bool isVisible) { foreach (Control control in controls) { if (String.Compare(control.Name, controlName, true)) == 0) { control.Visible = isVisible; return; } }
From the form class you can use it like this:
SetVisible(this, "txtName", true);
You might want to call this function recursively if you use control containers like Panel.
HTH, Alexander
"Robert Megee" <rm*****@comcast.net> wrote in message news:u0********************************@4ax.com. .. I'd like to be able to make a web controls such as a textbox either visible or not-visible by using the name of the textbox in a string and using that string in some command. sort of like: string str1; . . . str1 = "textbox1"; . . . @str1.Visible = true;
where the @ would mean substitue the value of the string in this context.
I've seen a reference to pointers such as are used in C, but I can't find any examples. Perhaps this is a way to do this.
Thanks,
Robert
Alexander
Combine the answers from Robbe and Robbert and than you have a webform
solution.
A sample modify it for your own needs.
\\\
Control frm = this.FindControl("Form1");
foreach (Control ctl in frm.Controls)
if (ctl is Button)
((Button) ctl).BackColor =
System.Drawing.Color.Azure;
///
I hope this helps,
Cor This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: James |
last post by:
I have a from with 2 fields:
Company & Name
Depening which is completed, one of the following queries will be run:
if($Company){
$query = "Select C*
From tblsample
Where ID = $Company...
|
by: Scott D |
last post by:
I am trying to check and see if a field is posted or not, if not
posted then assign $location which is a session variable to
$location_other. If it is posted then just assign it to...
|
by: Nick |
last post by:
Can someone please tell me how to access elements from a multiple
selection list? From what ive read on other posts, this is correct. I
keep getting an "Undefined variable" error though...
Form...
|
by: Alexander Ross |
last post by:
I have a variable ($x) that can have 50 different (string) values. I want
to check for 7 of those values and do something based on it ... as I see it
I have 2 options:
1) if (($x=="one") ||...
|
by: Dan Foley |
last post by:
This script runs fine, but I'd like to know why it's so slow.. Thanks
for any help out there on how i can make it faster (it might take up
to 5 min to write these 3 export files whith 15 records...
|
by: Lee Redeem |
last post by:
Hi there
I've created abd uploaded this basic PHP script:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<H1 align="center">
|
by: christopher vogt |
last post by:
Hi,
i'm wondering if there is something like $this-> to call a method inside
another method of the same class without using the classname in front.
I actually use
class TEST
{
function...
|
by: Phil Powell |
last post by:
Ok guys, here we go again!
SELECT s.nnet_produkt_storrelse_navn
FROM nnet_produkt_storrelse s, nnet_produkt_varegruppe v,
nnet_storrelse_varegruppe_assoc sv, nnet_produkt p
WHERE...
|
by: Michel |
last post by:
a site like this
http://www.dvdzone2.com/dvd
Can you make it in PHP and MySQL within 6 weeks?
If so, send me your price
2 a r a (at) p a n d o r a . b e
|
by: Maciej Nadolski |
last post by:
Hi!
I can`t understand what php wants from me:( So:
Cannot send session cache limiter - headers already sent (output started at
/home/krecik/public_html/silnik.php:208) in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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: 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...
|
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...
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |