Passing panel id to a subroutine

James

Well-known member
Joined
Oct 3, 2002
Messages
78
I am trying to passing a panel id to to a sub routine with a onclick on a button with VB.Net

I have several panels that I want to make visible or invisible, I want to create one sub to the same routine.

ex.


sub runIt(a as object, e as eventargs, pnlName as string)
if a.text="+" then
pnlName.visible=true
pnlTravel.visible=true This works fine
a.text="-"
else
pnlName.visible=false
pnlTravel.visible=false this works fine
a.text="+"
end if
End sub


<asp:Button id="btnAdd2" onclick="runIt(pnlTravel)" runat="server" Font-Size="XX-Small" BorderStyle="Solid" Text="+" BackColor="White" BorderColor="DarkGray" />
<asp:Panel id="pnlTravel" runat="server">My code goes here</asp:Panel>

Please help Im new to .NET

James
 
Pass the panel itself, not the name of it. Declare the parameter as type Panel, and you should be all set.
 
Ive declare the parameter as a panel. But how do I pass the panel itself? can you show me an example?
sub runIt(a as object, e as eventargs, pnlName as panel)
if a.text="+" then
pnlName.visible=true
a.text="-"
else
pnlName.visible=false
a.text="+"
end if
End sub

<asp:Button id="btnAdd2" onclick="runIt(pnlTravel)" runat="server" Font-Size="XX-Small" BorderStyle="Solid" Text="+" BackColor="White" BorderColor="DarkGray" />
<asp:Panel id="pnlTravel" runat="server">My code goes here</asp:Panel>

Thanks,

James
 
I dont have much experience in ASP.NET but that looks like it should work - can you elaborate on what error you get and where?
 
When I pass the panel name to the subroutine The subroutine is expecting values for "a as object, e as eventargs". If I take them out of the subroutine. I get a message telling me I need them. Is there a way I can pass the object and eventargs with the panel name?

James
 
If you place your routine in the code-behind, theres no reason why it doesnt work.
Code:
public sub runIt(a as object, e as eventargs, pnlName as panel)
    pnlName.visible=true
end sub
 
I dont believe onClick (and all events for that matter) excepts anything other than the subs name, nor do you need it to, since you already know what panel youre going to hide.
 

Similar threads

Back
Top