2 Replies - 149 Views - Last Post: 30 April 2019 - 11:36 AM Rate Topic: -----

#1 DarenR   User is offline

  • D.I.C Lover

Reputation: 602
  • View blog
  • Posts: 3,993
  • Joined: 12-January 10

how to force a button click event to fire before onload fires again

Posted 30 April 2019 - 09:40 AM

ok here is the scenario

the client will have the ability to add items dynamically to a table
when they click the new button all the dynamic items should be removed

the issue:
i have my items stored in a session and

page init and page load always load before the button click event so the session is never cleared


 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       
      '  Dim btn as Button = Nothing
      
        LoadValues()
       
      

    End Sub
    Protected sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        if Not IsPostBack then
              callTheLoad()
         End If
        if (Request("newHourBtn") IsNot Nothing) then
            dim int As Integer = 1
        end if
        if(IsPostBack) 
           
           
            if (Session("mySession") IsNot Nothing) 
                callTheLoad()
                Dim testSession = TryCast(Session("mySession"), List(Of TableRow))
                If Not IsNothing(testSession)
                    For Each row As TableRow In testSession
                        reasonsTable.Controls.Add(row)
                    Next
                end if
            End If
        end if
    End sub



the clear button:
Protected Sub newHourBtn_onclick(sender As Object, e As EventArgs)
       clearFields()
    End Sub
    Protected Sub clearFields()
        
        Session("mySession")= nothing
      
    End Sub





any thoughts on how i can clear the session before the page load?

Is This A Good Question/Topic? 0
  • +

Replies To: how to force a button click event to fire before onload fires again

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14994
  • View blog
  • Posts: 59,870
  • Joined: 12-June 08

Re: how to force a button click event to fire before onload fires again

Posted 30 April 2019 - 10:06 AM

Perhaps reorder the page load to 'page load complete'?
https://www.c-sharpc...les-in-Asp-Net/
Was This Post Helpful? 1
  • +
  • -

#3 DarenR   User is offline

  • D.I.C Lover

Reputation: 602
  • View blog
  • Posts: 3,993
  • Joined: 12-January 10

Re: how to force a button click event to fire before onload fires again

Posted 30 April 2019 - 11:36 AM

View Postmodi123_1, on 30 April 2019 - 01:06 PM, said:

Perhaps reorder the page load to 'page load complete'?
https://www.c-sharpc...les-in-Asp-Net/



youre the man modi

page load complete did the trick

  protected sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs)  Handles Me.LoadComplete 
    'if Not IsPostBack then
    'callTheLoad()
    'End If
       if btnClicked = "NH" Then

       else
            if(IsPostBack) 
                 
                if (Session("mySession") Is Nothing) 
                callTheLoad()
                Dim testSession = TryCast(Session("mySession"), List(Of TableRow))
                     If Not IsNothing(testSession)
                        For Each row As TableRow In testSession
                        reasonsTable.Controls.Add(row)
                        Next
                     end if
              
            End If
                if (Session("mySession").count > 0 and btnClicked = "NR") then
                   Dim testSession = TryCast(Session("mySession"), List(Of TableRow))
                    If Not IsNothing(testSession)
                        For Each row As TableRow In testSession
                            reasonsTable.Controls.Add(row)
                        Next
                    end if
                End If
                    
                if (Session("mySession").count > 0 and btnClicked <> "NR") then
                    callTheLoad()
                    Dim testSession = TryCast(Session("mySession"), List(Of TableRow))
                    If Not IsNothing(testSession)
                        For Each row As TableRow In testSession
                            reasonsTable.Controls.Add(row)
                        Next
                    end if
                End If
            
            end if
       end if
   
    end sub

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1