locked
2 buttons RRS feed

  • Question

  • User-1767698477 posted

    I have 2 nav buttons. One is to go to the next page, and when you press the button, the data is saved to the database.  The other button also saves the data but immediately exits to the default.aspx page.  I don't want to have to repeat all my code twice in every code behind page.

    How can I structure it so that all my code to test values put into controls on the page and save to db is only in one of the subs? I was thinking about creating a session variable on the fly to store Session("Exit") but then how would I redirect the eventargs from saveexit_Click to the next1_click sub ? Once the processing is done in Next1_click I can check the Session variable to determine which way to redirect. Is there another way?

    Protected Sub SaveExit_Click(sender As Object, e As System.EventArgs) Handles SaveExit.Click

    End Sub

    Protected Sub Next1_Click(sender As Object, e As EventArgs) Handles Next1.Click

    End Sub

    Thursday, April 22, 2021 1:48 AM

Answers

  • User1535942433 posted

    Hi sking,

    As far as I think,you could use EventHandler delegate and then define your own delegate to use it as parameter. 

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2021 6:17 AM

All replies

  • User1535942433 posted

    Hi sking,

    According to your description,as far as I think,you could create a button to save the data to database  in the master page. And the exit and next button only exit and next operations.

    Best regards,

    Yijing Sun

    Thursday, April 22, 2021 6:26 AM
  • User-1767698477 posted

    Hi Yij,Sun,

    That is an interesting concept. I don't understand how to implement that however. The event args have to get transferred into the sub processing the click event:

    Protected Sub SaveExit_Click(sender As Object, e As System.EventArgs) Handles SaveExit.Click

    After I click the button and the program starts the SaveExit.Click sub, is there a way to forward the event  args to another sub after I set a session variable?

    Monday, April 26, 2021 1:03 AM
  • User1535942433 posted

    Hi sking,

    As far as I think,you could use EventHandler delegate and then define your own delegate to use it as parameter. 

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 28, 2021 6:17 AM
  • User-1767698477 posted

    Ok, thanks. I have to do some research on this. I found this page here and there are more.

    https://stackoverflow.com/questions/4142728/vb-net-passing-an-event-as-a-parameter

    Thursday, April 29, 2021 2:50 AM