Click to See Complete Forum and Search --> : Find Control Problems


lmf232s
06-20-2006, 02:10 PM
This code will not work

Dim PanelId as String = "Panel1"

Dim P As Panel
P = FindControl(PanelId)
If Not P Is Nothing Then
P.Visible = True
End If

This code will work

Me.Panel1.Visible = True


All i can add is that the site uses a namespace and some page template thing that ends up rendering all the id's of the elements like this:
_PageTemplate_innerHolder_Panel1

I dont think this should matter since im trying to access in the code behind file. I know that if i want to access the panel through javascript i have to refer to
w/ the entire name _PageTemplate_innerHolder_Panel1.

EDIT
Actually this problem might be related to all the crap i have to include on the page because of the namespace and the damn custom templates.
If i just create a blank page w/ none of that crap on it, then the code i posted works just fine.

Any ideas on what i could be missing to allow this code to work when i have to include all the page template crap?
Any ideas

lmf232s
06-20-2006, 03:20 PM
Ok i have found the reason and the problem i just dont know the solution.

There is a templatemaker.vbproj that gets a Registered on the aspx page.
Then you wrap the tag around the contents of the page.

Here is a sample of what the page will look like

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="MyTestPage1.aspx.vb" Inherits="IDIWeb.web.MyTestPage1"%>
<%@ Register TagPrefix="gftp" NameSpace="IDIWeb.TemplateMaker" Assembly="TemplateMaker" %>

<body MS_POSITIONING="GridLayout">
<gftp:pagebody id="pbdTemplate" runat="server">
<form id="Form1" method="post" runat="server">
<asp:Panel ID=Panel0 Visible=False Runat="server">
This is my test.
</asp:Panel>
</form>
</gftp:pagebody>
</body>


If i remove the <gftp:> tag from the page then i am able to use the FindControl and actually find the panel.

I guess my question now is, Is there a way to still use the FindControl in this situation?

AlecW
06-21-2006, 11:11 AM
You would need to use the findcontrol method of the gftp control. This will allow you to find the control within this control. If it is not there, that means they did not inherit from control base.

lmf232s
06-21-2006, 03:55 PM
alex,

Would you mind showing the syntax on how you might do that as i tried many different ways and was unable to get it to work. Chances are maybe i had the correct syntax but was still unable to find the control.

On the other hand i did get this to work by doing a recursive search on all the controls on the page and finding the 1 i was looking for.

But if there is just a simple apprach to just say something like

gftp.FindControl("NameofControl")

Then i would give that a shot. Again im just not sure what the syntax should look like.

AlecW
06-21-2006, 04:02 PM
You are correct if your code sample. If the gftp component was written correctly, it should have inherited the "Control" class. This should allow it to have the .FindControl method, so you would be able to use gftp.FindControl(control name here).

I hope this helps you.