Results 1 to 2 of 2

Thread: Help passing web control id to a sub routine

  1. #1

    Thread Starter
    Registered User
    Join Date
    Jul 2002
    Posts
    80

    Question Help passing web control id to a sub routine

    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

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    Here is an example i wrote, which sets the first control to visible and the second control to invisible:

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         ShowPanel("Panel2", "Panel1")
    3.     End Sub
    4.  
    5.     Function ShowPanel(ByVal strPanel As String, ByVal strHide As String)
    6.         Dim x As Control
    7.         Dim myFrm As Control
    8.         Label1.Text = Panel1.Parent.ID()
    9.         For Each myFrm In Me.Controls
    10. 'Find the Form
    11.             If myFrm.ID = "Form1" Then
    12.                 Exit For
    13.             End If
    14.         Next
    15.         For Each x In myFrm.Controls
    16.             Select Case LCase(x.ID)
    17.                 Case LCase(strPanel)
    18.                     x.Visible = True
    19.  
    20.                 Case LCase(strHide)
    21.                     x.Visible = False
    22.             End Select
    23.         Next
    24.     End Function
    25.  
    26.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    27.         ShowPanel("Panel1", "Panel2")
    28.     End Subp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width