Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Variables gone during grid insert command

Variables gone during grid insert command

Scheduled Pinned Locked Moved ASP.NET
csshelp
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    byka
    wrote on last edited by
    #1

    Please help me.. I am trying to store variable in a class however during grid insert all variable gone. Below is my code

    Dim StateTemplate As New StateTemplate

    Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
    Try
    Dim StateTemplate As New StateTemplate
    With StateTemplate
    .YearCode = ddlPlanYears.SelectedValue
    .State = ddlState.SelectedItem.ToString
    End With
    ...
    Private Sub rgExclusions_InsertCommand...
    StateTemplate is empty here

    L 1 Reply Last reply
    0
    • B byka

      Please help me.. I am trying to store variable in a class however during grid insert all variable gone. Below is my code

      Dim StateTemplate As New StateTemplate

      Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
      Try
      Dim StateTemplate As New StateTemplate
      With StateTemplate
      .YearCode = ddlPlanYears.SelectedValue
      .State = ddlState.SelectedItem.ToString
      End With
      ...
      Private Sub rgExclusions_InsertCommand...
      StateTemplate is empty here

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      byka wrote:

      StateTemplate is empty here

      Of course it is, because you used a different StateTemplate object within your subroutine. Delete the declaration between the Try and With statements.

      B 1 Reply Last reply
      0
      • L Lost User

        byka wrote:

        StateTemplate is empty here

        Of course it is, because you used a different StateTemplate object within your subroutine. Delete the declaration between the Try and With statements.

        B Offline
        B Offline
        byka
        wrote on last edited by
        #3

        I delete it. and it still not working

        Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
        With StateTemplate
        .YearCode = ddlPlanYears.SelectedValue
        .State = ddlState.SelectedItem.ToString
        End With

        L Richard DeemingR 2 Replies Last reply
        0
        • B byka

          I delete it. and it still not working

          Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
          With StateTemplate
          .YearCode = ddlPlanYears.SelectedValue
          .State = ddlState.SelectedItem.ToString
          End With

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Where have you declared your StateTemplate object? What happens to it after you return from the btnLoad_Click event? Please expand on the expression "it still not working"; we cannot guess what that means.

          B 1 Reply Last reply
          0
          • L Lost User

            Where have you declared your StateTemplate object? What happens to it after you return from the btnLoad_Click event? Please expand on the expression "it still not working"; we cannot guess what that means.

            B Offline
            B Offline
            byka
            wrote on last edited by
            #5

            I declare after Inherits System.Web.UI.Page I don't do anything with it after btnClick event

            L 1 Reply Last reply
            0
            • B byka

              I declare after Inherits System.Web.UI.Page I don't do anything with it after btnClick event

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              byka wrote:

              I don't do anything with it after btnClick event

              So what is your problem?

              B 1 Reply Last reply
              0
              • L Lost User

                byka wrote:

                I don't do anything with it after btnClick event

                So what is your problem?

                B Offline
                B Offline
                byka
                wrote on last edited by
                #7

                the variable is empty during grid insert

                L 1 Reply Last reply
                0
                • B byka

                  the variable is empty during grid insert

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I'm sorry, but there is really no point in posting these vague statements and expecting us to guess what your application is doing. Show where the variable is set up , and where you try to use it, and explain the exact sequence of events that should make this happen. If you need to collect further information then use your debugger during a test run of your code.

                  1 Reply Last reply
                  0
                  • B byka

                    I delete it. and it still not working

                    Private Sub btnLoad_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoad.Click
                    With StateTemplate
                    .YearCode = ddlPlanYears.SelectedValue
                    .State = ddlState.SelectedItem.ToString
                    End With

                    Richard DeemingR Offline
                    Richard DeemingR Offline
                    Richard Deeming
                    wrote on last edited by
                    #9

                    I'm guessing that there is a post-back between the btnLoad_Click event handler and the rgExclusions_InsertCommand event handler? When an ASP.NET page posts back, the request is served by a new instance of the page class. Once the page has been rendered, that instance of the class is discarded, along with the value of any fields. That is why your StateTemplate field is not persisting between requests. If you want to save the values between requests, then you'll need to store them in ViewState: Beginner's Guide To View State [^] Understanding ASP.NET View State[^]


                    "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                    "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups