FindControl help...please

D

Dave

I have a web page that I'm trying to toggle between current data and
archived data. So far so good. To preserver the integrity of the
archived data, I need to disable the Edit, Delete, and New links in
the Form View. The below code is what I've been trying to use, and
I've tried it in various events with no luck. I need some help.

Control btn1 = this.fvCapture.FindControl("EditButton");
Control btn2 = fvCapture.FindControl("NewButton");
Control btn3 = fvCapture.FindControl("DeleteButton");
Button b1 = btn1 as Button;
Button b2 = btn2 as Button;
Button b3 = btn3 as Button;
if (b1 != null)
{
b1.Enabled = false;
}
if (b2 != null)
{
b2.Enabled = false;
}
if (b3 != null)
{
b3.Enabled = false;
}

Thankyou
 
L

Liz

Dave said:
I have a web page that I'm trying to toggle between current data and
archived data. So far so good. To preserver the integrity of the
archived data, I need to disable the Edit, Delete, and New links in
the Form View. The below code is what I've been trying to use, and
I've tried it in various events with no luck. I need some help.

Hard to figure your context ... but this worked fine for me:

Button b = (Button)FormView1.FindControl("editButton");

b.Enabled = false;

I just handled a button on dropped on the FormView to look at this ... don't
know what event you're trying to handle but not sure why it should matter ..
 
L

Liz

I have a web page that I'm trying to toggle between current data and
archived data. So far so good. To preserver the integrity of the
archived data, I need to disable the Edit, Delete, and New links in
the Form View. The below code is what I've been trying to use, and
I've tried it in various events with no luck. I need some help.

Control btn1 = this.fvCapture.FindControl("EditButton");
Control btn2 = fvCapture.FindControl("NewButton");
Control btn3 = fvCapture.FindControl("DeleteButton");
Button b1 = btn1 as Button;
Button b2 = btn2 as Button;
Button b3 = btn3 as Button;
if (b1 != null)
{
b1.Enabled = false;
}
if (b2 != null)
{
b2.Enabled = false;
}
if (b3 != null)
{
b3.Enabled = false;
}

btw, I also tried your construct:

Control b2 = FormView1.FindControl("newButton");

Button b22 = b2 as Button;

b22.Enabled = false;

and it worked too .... apparently, your FindControl call is not finding;
must be in the wrong level of the containment hierarchy ... if you cannot
get this going you could just try to handle the database events and cancel
them before they occur if the program state is "archive" ... not as elegant
of course .. but workable if you're in a bind
 
D

Dave

Liz,
Thanks for your help and Comments. Where would you suggest that I put
it in the containment hierarchy?

Dave
 
L

Liz

Liz,
Thanks for your help and Comments. Where would you suggest that I put
it in the containment hierarchy?

where it belongs? lol ... sorry; I'm not all that clear on this issue and
only have a snippet of your code, and I'd like to get clear on it;
meanwhile, have a look at these links which appear to be a good start on
sorting it out:

http://msdn2.microsoft.com/en-us/library/1d04y8ss(vs.80).aspx
http://msdn2.microsoft.com/en-us/library/txxbk90b(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/hw8sf6fb(VS.80).aspx

apparently fvCapture is not adequate as an unambiguous naming container in
your code .. you might turn on Trace and look at the Control tree too ..

maybe someone else has a firm grasp on this ... I think part of the problem
is that controls which use templates can generate multiple instances of a
child controls that have to be resolved through reference to the particular
naming container in which they reside .. and that seems to be the case even
where, for example, your button only exists in one of the templates and does
not repeat (or maybe not ... because I *can* get a reference to the button
in my FormView)

anyway, the MSDN articles should be a start ... let us know when this is
fully resolved !

L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top