在后面的aspx代码中调用动态页面上的函数

时间:2014-09-25 16:53:30

标签: asp.net vb.net

我有一个函数loadList(),它根据我们的数据库加载一个动态列表。

element_maint.aspx.vb

Private Sub loadList()
    'load sub-organizations
    Dim lstItems As cihElementList = Nothing

    Dim thr As TableHeaderRow = Nothing
    Dim tr As TableRow = Nothing
    Dim tc As TableCell = Nothing
    Dim lnk1 As HyperLink = Nothing
    Dim lnk2 As HyperLink = Nothing

    Dim item As cihCategoryOrgDef = Nothing

    Dim rvd As Routing.RouteValueDictionary = Nothing
    Dim rvdDeactivate As Routing.RouteValueDictionary = Nothing
    Dim vpd As Routing.VirtualPathData = Nothing
    Dim vpdDeactivate As Routing.VirtualPathData = Nothing

    Dim btnAction As cihBootstrapButtonDropdown = Nothing

        '*****************************************
        'Build the action drop down
        'Build the action button
        '*****************************************
        btnAction = New cihBootstrapButtonDropdown("Action", cihBootstrapButtonDropdown.buttonTypes.link)

        'Existing Items
        lstItems = New cihElementList()
        lstItems.loadForOrganization(orgId)

        For Each ele As cihElementList.elementShort In lstItems.listOfElements
            tr = New TableRow

            lnk1 = New HyperLink
            lnk1.Text = "Edit"
            lnk2 = New HyperLink
            lnk2.Text = "Deactivate"

            rvd = New Routing.RouteValueDictionary(New With {.action = "edit", .elementid = ele.elementId.ToString()})
            rvdDeactivate = New Routing.RouteValueDictionary(New With {.action = "deactivate", .elementid = ele.elementId.ToString()})
            vpd = Routing.RouteTable.Routes.GetVirtualPath(Nothing, "element_maint", rvd)
            vpdDeactivate = Routing.RouteTable.Routes.GetVirtualPath(Nothing, "element_deactivate", rvdDeactivate)


            btnAction.addLink("Edit", vpd.VirtualPath, False)

            If (ZenCommon.CurrentUser.secLevelId = cihCommonDef.FullSiteAdmin Or ZenCommon.CurrentUser.secLevelId = cihCommonDef.OrganizationAdmin) Then 'if SuperAdmin or Campus Admin
                'Need Help here
                btnAction.addLink("Deactivate", vpdDeactivate.VirtualPath, False) 
            End If

            ZenCommon.AddCell(tr, ele.eleDescr, , , "200px")

            tc = New TableCell
            tc.Controls.Add(New LiteralControl(btnAction.buttonHTML))
            tc.Style.Add("width", "50px")

            tr.Cells.Add(tc)

            Me.tblList.Rows.Add(tr)
        Next

End Sub


Private Sub deactivateTag()
       'Goto Database, flag 'tag' as inactive
End Sub

我希望btnAction.addLink(" Deactivate")在我的aspx.vb中调用一个函数。该函数将标记标记为非活动状态。

现在'编辑"按钮(在'停用'按钮上方,将转到新页面以允许您编辑它。我明白了。但是当我点击我的'停用&时,有没有办法实现它#39;按钮只会调用我的deactivateTag()

1 个答案:

答案 0 :(得分:1)

在您的代码隐藏中,您可以更改方法签名

Protected Sub deactivateTag(ByRef sender as Object, ByRef e as System.EventArgs) Handles btnDeactivate.Click

和你的标记

<asp:Button ID="btnDeactivate" onClick="deactivateTag" />

或者您可以为按钮添加点击事件,并从该事件中调用您的函数。

 Protected Sub btnDeactivate_Click(ByRef sender as Object, ByRef e as System.EventArgs) Handles btnDeactivate.Click
 deactivateTag()
End Sub

这取决于您是否需要从其他控件调用deactivateTag。