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. CS0103 variable does not exist in this context

CS0103 variable does not exist in this context

Scheduled Pinned Locked Moved Web Development
csharpsysadminhelpquestion
5 Posts 2 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.
  • S Offline
    S Offline
    scratchmonkey
    wrote on last edited by
    #1

    I have a persistent build error that I'm finding very difficult to track down. Basically, I have a Default.aspx page that defines a drop-down list like so: runat="server" DataSourceID="user_data_source" DataTextField="user_name" DataValueField="user_name" AutoPostBack="true" > Then, in the code-behind (C#), I attempt to assign the value of the selected item to a string variable like so: string username = ""; username = ddl_userName.SelectedValue; This generates a CS0103 error that says:

    The name 'ddl_userName' does not exist in the current context

    It seems like a scoping error, but the code file is correctly identified in the page directive, and everything appears to be correct. Any ideas? Thanks

    Steve EcholsS 1 Reply Last reply
    0
    • S scratchmonkey

      I have a persistent build error that I'm finding very difficult to track down. Basically, I have a Default.aspx page that defines a drop-down list like so: runat="server" DataSourceID="user_data_source" DataTextField="user_name" DataValueField="user_name" AutoPostBack="true" > Then, in the code-behind (C#), I attempt to assign the value of the selected item to a string variable like so: string username = ""; username = ddl_userName.SelectedValue; This generates a CS0103 error that says:

      The name 'ddl_userName' does not exist in the current context

      It seems like a scoping error, but the code file is correctly identified in the page directive, and everything appears to be correct. Any ideas? Thanks

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      Do you have id="ddl_userName" on your asp:dropdownlist? C# is also case senesitive.


      - S 50 cups of coffee and you know it's on!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      S 1 Reply Last reply
      0
      • Steve EcholsS Steve Echols

        Do you have id="ddl_userName" on your asp:dropdownlist? C# is also case senesitive.


        - S 50 cups of coffee and you know it's on!

        S Offline
        S Offline
        scratchmonkey
        wrote on last edited by
        #3

        ARRGGHH -- yes, the name is on the drop-down lists ID property. I thought I proofed that post, I'll have to put up the actual code tomorrow. But the name is the same in both the .aspx and the .cs file. I typed it the same, I copied - pasted it in, and I chose it from the intellisense options. All three ways produced the same error. my co-worker actually may have found the problem, I'll check it in the morning and post it here if he's right.

        Steve EcholsS 1 Reply Last reply
        0
        • S scratchmonkey

          ARRGGHH -- yes, the name is on the drop-down lists ID property. I thought I proofed that post, I'll have to put up the actual code tomorrow. But the name is the same in both the .aspx and the .cs file. I typed it the same, I copied - pasted it in, and I chose it from the intellisense options. All three ways produced the same error. my co-worker actually may have found the problem, I'll check it in the morning and post it here if he's right.

          Steve EcholsS Offline
          Steve EcholsS Offline
          Steve Echols
          wrote on last edited by
          #4

          I know I've had this happen to me before, just can't remember the circumstances off the top of my head. Possibly the name of the class in the .cs file doesn't match the inherits attribute on the page tag? Let us know what you find out.


          - S 50 cups of coffee and you know it's on!

          • S
            50 cups of coffee and you know it's on!
            Code, follow, or get out of the way.
          S 1 Reply Last reply
          0
          • Steve EcholsS Steve Echols

            I know I've had this happen to me before, just can't remember the circumstances off the top of my head. Possibly the name of the class in the .cs file doesn't match the inherits attribute on the page tag? Let us know what you find out.


            - S 50 cups of coffee and you know it's on!

            S Offline
            S Offline
            scratchmonkey
            wrote on last edited by
            #5

            OK, the code in my original post should have looked like this: aspx: <asp:DropDownList ID="ux_ddl_userName" runat="server" DataSourceID="user_data_source" DataTextField="user_name" DataValueField="user_name" AutoPostBack="true" > </asp:DropDownList> .cs: string username = ""; username = this.ux_ddl_userName.SelectedValue; The file names were Default.aspx and Default.aspx.cs, and the class name was _Default. The code-behind and the class were correctly identified in the Codefile and inherits properties of the page directive. The "fix" ended up being to change the file names to DevDefault and change the class name to DevDefault. The original file and class names were generated by the IDE. I did find in the project, that there was a Default3 file that identified the same class in a different file, so that may have been where the conflict was. If it was looking at that _Default class, then the error would have made sense, since it was essentially empty. In fact, I'm sure that's what it was, since typing the control name didn't bring up the intellisense listing, but preceding the control name with "this" did bring it up. It was a name clash. Thanks.

            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