Which button was clicked to open form

拈花ヽ惹草 提交于 2019-12-02 06:00:57

Well suppose to define at the global level an enum like this

Public Enum CommandAction
    Create
    Modify 
    Delete
End Enum

Now in the code used to launch your second form to execute the Add command, you could write code like this (of course you repeat the same but varying the CommandAction in the other buttons).

Dim myFormInstance = new MyForm(CommandAction.Create)
myFormInstance.ShowDialog()

Finally, add a specfic constructor for your second form (MyForm in this example). A constructor that receives and saves for future usage a CommandAction

Public Class MyForm
    Dim cmd as CommandAction

    Public Sub New(command as CommandAction )
         InitializeComponent()
         cmd = command
    End Sub
    Public Sub New()
         InitializeComponent()
         cmd = CommandAction.Create ' Set a default'
    End Sub
End Class

Now in the code where you need to decide which kind of action to execute, just look at the value of the global cmd variable and execute the appropriate block of code

NOTE Adding a specific constructor to a form class requires the explicit presence of the standard empty constructor.

first put a hidden field with some name like "clicked". Make a javascript function with one parameter to put values in to the hidden field. Call the function on click of every button but set some specific value for each button. In this way you will be able to run right code for each button on submit. If not understand then do tell me, i'll help you in the code.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!