James Posted November 21, 2002 Posted November 21, 2002 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 I'm new to .NET James Quote
*Gurus* divil Posted November 21, 2002 *Gurus* Posted November 21, 2002 Pass the panel itself, not the name of it. Declare the parameter as type Panel, and you should be all set. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
James Posted November 21, 2002 Author Posted November 21, 2002 I've 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 Quote
*Gurus* divil Posted November 21, 2002 *Gurus* Posted November 21, 2002 I don't have much experience in ASP.NET but that looks like it should work - can you elaborate on what error you get and where? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
James Posted November 21, 2002 Author Posted November 21, 2002 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 Quote
Moderators Robby Posted November 21, 2002 Moderators Posted November 21, 2002 If you place your routine in the code-behind, there's no reason why it doesn't work. public sub runIt(a as object, e as eventargs, pnlName as panel) pnlName.visible=true end sub Quote Visit...Bassic Software
Moderators Robby Posted November 21, 2002 Moderators Posted November 21, 2002 what is 'a as object' supposed to be? Quote Visit...Bassic Software
*Gurus* Derek Stone Posted November 21, 2002 *Gurus* Posted November 21, 2002 I don't believe onClick (and all events for that matter) excepts anything other than the sub's name, nor do you need it to, since you already know what panel you're going to hide. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.