~工作簡化,不再是難事~

2016-06-14

〔ASP.NET〕利用按鈕Command呼叫特定程式 / CommandName&CommandArgument Code Behind OnClick

不管是Button or LinkButton...皆有CommandName & CommandArgument屬性,可產生各別Click事件去傳遞值
若同一頁面上之Button皆有相同的行為,則可設定其OnCommand屬性來連結後端觸發事件,並利用CommandName & CommandArgument來傳遞設定值

例如:
前端程式碼
<asp: LinkButton ID ="lkb01" runat ="server" OnCommand ="FuncGo" CommandName="R1_001"></asp :LinkButton>


後端程式碼
Protected Sub FuncGo(sender As Object, e As CommandEventArgs)
    Select Case e.CommandName
        Case "R1_001"
            'do somthing
        Case Else
    End Select

End Sub

0 意見:

張貼留言

Popular Posts

Copyright © 2016 Scenic's BOX. 技術提供:Blogger.