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. Use variable from the code behind

Use variable from the code behind

Scheduled Pinned Locked Moved ASP.NET
question
8 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.
  • K Offline
    K Offline
    Kefaleas Stavros
    wrote on last edited by
    #1

    I am using this variable from the code behind :

    public string UserID; //globally declare the UserId
    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
    MembershipUser myObject = Membership.GetUser();
    UserID = myObject.ProviderUserKey.ToString();
    }

    I am trying to use the variable in the INSERT command in the aspx file but it seems that the following command does not work,any ideas why? InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" Thanks!

    J C 2 Replies Last reply
    0
    • K Kefaleas Stavros

      I am using this variable from the code behind :

      public string UserID; //globally declare the UserId
      protected void RadGrid1_PreRender(object sender, EventArgs e)
      {
      MembershipUser myObject = Membership.GetUser();
      UserID = myObject.ProviderUserKey.ToString();
      }

      I am trying to use the variable in the INSERT command in the aspx file but it seems that the following command does not work,any ideas why? InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" Thanks!

      J Offline
      J Offline
      John Gathogo
      wrote on last edited by
      #2

      What about

      InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" + UserID + "')"

      Assuming that you are doing this from within RadGrid1_PreRender routine.

      K 1 Reply Last reply
      0
      • J John Gathogo

        What about

        InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '" + UserID + "')"

        Assuming that you are doing this from within RadGrid1_PreRender routine.

        K Offline
        K Offline
        Kefaleas Stavros
        wrote on last edited by
        #3

        Thnx for answering but I want to use the variable in the aspx file not in the code behind file.

        1 Reply Last reply
        0
        • K Kefaleas Stavros

          I am using this variable from the code behind :

          public string UserID; //globally declare the UserId
          protected void RadGrid1_PreRender(object sender, EventArgs e)
          {
          MembershipUser myObject = Membership.GetUser();
          UserID = myObject.ProviderUserKey.ToString();
          }

          I am trying to use the variable in the INSERT command in the aspx file but it seems that the following command does not work,any ideas why? InsertCommand="INSERT INTO table (column1, column2) VALUES (value1, '<%=UserID %>')" Thanks!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          It would help if you defined 'does not work', but I thought that using code blocks like this only worked for properties, not for public variables.

          Christian Graus Driven to the arms of OSX by Vista.

          K 1 Reply Last reply
          0
          • C Christian Graus

            It would help if you defined 'does not work', but I thought that using code blocks like this only worked for properties, not for public variables.

            Christian Graus Driven to the arms of OSX by Vista.

            K Offline
            K Offline
            Kefaleas Stavros
            wrote on last edited by
            #5

            What I mean is that if I use sql management studio and enter the insert query manually there is no problem.

            C 1 Reply Last reply
            0
            • K Kefaleas Stavros

              What I mean is that if I use sql management studio and enter the insert query manually there is no problem.

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              But what *is* the problem ? Is the value being passed back blank ? Is it incorrect ? Does it blow up ? Did you try using a property ?

              Christian Graus Driven to the arms of OSX by Vista.

              K 1 Reply Last reply
              0
              • C Christian Graus

                But what *is* the problem ? Is the value being passed back blank ? Is it incorrect ? Does it blow up ? Did you try using a property ?

                Christian Graus Driven to the arms of OSX by Vista.

                K Offline
                K Offline
                Kefaleas Stavros
                wrote on last edited by
                #7

                Can you give me a sample .aspx code of properly passing a value from the code behind? Thank you!

                C 1 Reply Last reply
                0
                • K Kefaleas Stavros

                  Can you give me a sample .aspx code of properly passing a value from the code behind? Thank you!

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  int _n; // this is a variable protected int N { get { return _n; } // this is a property } Wrap your variable in a property and then access the property.

                  Christian Graus Driven to the arms of OSX by Vista.

                  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