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. newbie question

newbie question

Scheduled Pinned Locked Moved ASP.NET
csharpquestionvisual-studio
9 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.
  • B Offline
    B Offline
    brian55
    wrote on last edited by
    #1

    I am using VS .net I have a session variable set in another frame that I want to use to determine what frame pages to display. I use this line to make the frame decision. "> I get the message CS0103: The name 'sAirportSelected' does not exist in the class or namespace 'ASP.MainIntroForm_aspx' My code behind is c# and the seesion variable is sAirportSelected. what am I doing wrong? Brian

    C 1 Reply Last reply
    0
    • B brian55

      I am using VS .net I have a session variable set in another frame that I want to use to determine what frame pages to display. I use this line to make the frame decision. "> I get the message CS0103: The name 'sAirportSelected' does not exist in the class or namespace 'ASP.MainIntroForm_aspx' My code behind is c# and the seesion variable is sAirportSelected. what am I doing wrong? Brian

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

      Well, for starters it looks to me like you're writing classic asp pages in C# instead of using ASP.NET the way it should be used. At a minimum, your src= block should call a method on the class that returns a string, instead of whacking code into the aspx. That's just ugly. Your code is expecting the page instance to have a variable called sAirportSelected. That's different to a variable of that name being shoved into the session. You should avoid using the session where you can, in any case. Christian Graus - Microsoft MVP - C++

      B 1 Reply Last reply
      0
      • C Christian Graus

        Well, for starters it looks to me like you're writing classic asp pages in C# instead of using ASP.NET the way it should be used. At a minimum, your src= block should call a method on the class that returns a string, instead of whacking code into the aspx. That's just ugly. Your code is expecting the page instance to have a variable called sAirportSelected. That's different to a variable of that name being shoved into the session. You should avoid using the session where you can, in any case. Christian Graus - Microsoft MVP - C++

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

        Thanks for the response. It seems to me that in the .net environment there should be a direct link between what is in the code behind and the aspx page. This is the assumption I have made. Thus given this premise I should have access to the varialbes in the code behind from the aspx page. In my case I simple referred to the variable and nested it in a if then statement. I used c# notation since this is what I used in the code behind. Clearly I have made some bad assumptions. Can you show me how the session variable should be reference and also show me how the statement should be executed in the HTML code. This may help me understand what is going on. Thanks

        C 1 Reply Last reply
        0
        • B brian55

          Thanks for the response. It seems to me that in the .net environment there should be a direct link between what is in the code behind and the aspx page. This is the assumption I have made. Thus given this premise I should have access to the varialbes in the code behind from the aspx page. In my case I simple referred to the variable and nested it in a if then statement. I used c# notation since this is what I used in the code behind. Clearly I have made some bad assumptions. Can you show me how the session variable should be reference and also show me how the statement should be executed in the HTML code. This may help me understand what is going on. Thanks

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

          brian55 wrote: It seems to me that in the .net environment there should be a direct link between what is in the code behind and the aspx page. That is correct. The page is linked to an instance of the class represented in the code behind. brian55 wrote: Thus given this premise I should have access to the varialbes in the code behind from the aspx page. In my case I simple referred to the variable and nested it in a if then statement. I used c# notation since this is what I used in the code behind. OK - if the variable existed in the code behind, and was not private, then this should have worked. I am assuming there was a property in the code behind that had that name, and which then accessed the session variable. Something like protected string sVarName { get { return Session["sVarName"]; } set { Session["sVarName"] = value; } } would do it, although I'd still advocate that all C# code in your aspx should be method calls, the actual code is cleaner in your code behind. Christian Graus - Microsoft MVP - C++

          B 1 Reply Last reply
          0
          • C Christian Graus

            brian55 wrote: It seems to me that in the .net environment there should be a direct link between what is in the code behind and the aspx page. That is correct. The page is linked to an instance of the class represented in the code behind. brian55 wrote: Thus given this premise I should have access to the varialbes in the code behind from the aspx page. In my case I simple referred to the variable and nested it in a if then statement. I used c# notation since this is what I used in the code behind. OK - if the variable existed in the code behind, and was not private, then this should have worked. I am assuming there was a property in the code behind that had that name, and which then accessed the session variable. Something like protected string sVarName { get { return Session["sVarName"]; } set { Session["sVarName"] = value; } } would do it, although I'd still advocate that all C# code in your aspx should be method calls, the actual code is cleaner in your code behind. Christian Graus - Microsoft MVP - C++

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

            Thanks for your patience. I am still confused...(but not as much)anyway here is what I think you are suggesting. My code is for the most part OK. In this reagrd my session variable is obtained as such in the code behind string sSelected; sSelected =(string) (Session["Selected"]); So now in the asps page (in the html code) is can simply refer to it and I do in the following command "> This line of code generates the following error The active schema does not support the element '% if....(everything in between) %' What is wrong? I suspect it has something to do with the definition within the page. the first line on my page is <%@ Page language="c#" Codebehind="MainIntroForm.aspx.cs" AutoEventWireup="false" Inherits="test.MainIntroForm" %> Thanks....

            C 1 Reply Last reply
            0
            • B brian55

              Thanks for your patience. I am still confused...(but not as much)anyway here is what I think you are suggesting. My code is for the most part OK. In this reagrd my session variable is obtained as such in the code behind string sSelected; sSelected =(string) (Session["Selected"]); So now in the asps page (in the html code) is can simply refer to it and I do in the following command "> This line of code generates the following error The active schema does not support the element '% if....(everything in between) %' What is wrong? I suspect it has something to do with the definition within the page. the first line on my page is <%@ Page language="c#" Codebehind="MainIntroForm.aspx.cs" AutoEventWireup="false" Inherits="test.MainIntroForm" %> Thanks....

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

              brian55 wrote: In this reagrd my session variable is obtained as such in the code behind string sSelected; sSelected =(string) (Session["Selected"]); So now in the asps page (in the html code) is can simply refer to it and I do in the following command You're relying on the code that sets the variable being run before the code in your page. It's a race condition, even if the order of operations makes it safe. Creating a property means that your code is run at the moment that you want it to, guarenteed. Making it all a method is even better. brian55 wrote: This line of code generates the following error The active schema does not support the element '% if....(everything in between) %' Is that an error, or a warning ? I get those from time to time, I ignore them. Oh, I see the problem. You're using double quotes twice. Src is being set to <%if sSelected=, then you have a close quotes, and the rest is shot to hell. Another reason that you should instead just have a method that you call to return the string you require, instead of putting code in your aspx. Or you can use single quotes in the src=, and double quotes within it, I believe. I don't know because I'd never code something this way ( I'd have src="<%GetFrameSource()%>' and a method that looks like the above in my code behind called GetFrameSource that returned a string ). Christian Graus - Microsoft MVP - C++

              B 1 Reply Last reply
              0
              • C Christian Graus

                brian55 wrote: In this reagrd my session variable is obtained as such in the code behind string sSelected; sSelected =(string) (Session["Selected"]); So now in the asps page (in the html code) is can simply refer to it and I do in the following command You're relying on the code that sets the variable being run before the code in your page. It's a race condition, even if the order of operations makes it safe. Creating a property means that your code is run at the moment that you want it to, guarenteed. Making it all a method is even better. brian55 wrote: This line of code generates the following error The active schema does not support the element '% if....(everything in between) %' Is that an error, or a warning ? I get those from time to time, I ignore them. Oh, I see the problem. You're using double quotes twice. Src is being set to <%if sSelected=, then you have a close quotes, and the rest is shot to hell. Another reason that you should instead just have a method that you call to return the string you require, instead of putting code in your aspx. Or you can use single quotes in the src=, and double quotes within it, I believe. I don't know because I'd never code something this way ( I'd have src="<%GetFrameSource()%>' and a method that looks like the above in my code behind called GetFrameSource that returned a string ). Christian Graus - Microsoft MVP - C++

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

                I think I am beginiing to get this. When you mean create a method you are essentially telling me to call a function or subroutine (old terminology, but one I understand). Ok I get this. I created the method public string GetFrameSource() { string sAirportSelected; sAirportSelected =(string) (Session["airportSelected"]); return sAirportSelected; } Then I tried to call the method or invoke it (I am not sure what term to use these days!) with this line "> When I do I get an error message that complains about the open bracket "(" and everything in between. the details are Line 11: namespace ASP { Line 12: using System; Line 13: using System.Collections; Line 14: using System.Collections.Specialized; Line 15: using System.Configuration; ..... this is what the debugger is complaining about: [http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,16): error CS1003: Syntax error, '(' expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1026: ) expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1023: Embedded statement cannot be a declaration or labeled statement http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1002: ; expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1001: Identifier expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1002: ; expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1525: Invalid expression term 'else'](http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,16): error CS1003: Syntax error, '(' expected
                http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1026: ) expected
                http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1023: Embedded statement cannot be a declaration or labeled statement
                http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1002: ; expected
                http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1001: Identifier expected
                http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1002: ; expected
                http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1525: Invalid expression term 'else'
                ) [

                C 1 Reply Last reply
                0
                • B brian55

                  I think I am beginiing to get this. When you mean create a method you are essentially telling me to call a function or subroutine (old terminology, but one I understand). Ok I get this. I created the method public string GetFrameSource() { string sAirportSelected; sAirportSelected =(string) (Session["airportSelected"]); return sAirportSelected; } Then I tried to call the method or invoke it (I am not sure what term to use these days!) with this line "> When I do I get an error message that complains about the open bracket "(" and everything in between. the details are Line 11: namespace ASP { Line 12: using System; Line 13: using System.Collections; Line 14: using System.Collections.Specialized; Line 15: using System.Configuration; ..... this is what the debugger is complaining about: [http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,16): error CS1003: Syntax error, '(' expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1026: ) expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1023: Embedded statement cannot be a declaration or labeled statement http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1002: ; expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1001: Identifier expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1002: ; expected http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1525: Invalid expression term 'else'](http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,16): error CS1003: Syntax error, '(' expected
                  http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1026: ) expected
                  http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,38): error CS1023: Embedded statement cannot be a declaration or labeled statement
                  http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1002: ; expected
                  http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,51): error CS1001: Identifier expected
                  http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1002: ; expected
                  http://localhost/SIMDAC Viewer/MainIntroForm.aspx(13,75): error CS1525: Invalid expression term 'else'
                  ) [

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

                  brian55 wrote: "> Good up to this point. You still have multi nested quotes, which means that the value for src is still the value from the first open quote to the first close quote. Your function should check the value in question and return one of the two aspx names accordingly, then your line will be src="<%GetFrameSource()%>" brian55 wrote: Much closer to understanding the bigger picture here.... Glad to hear it, hope this solves the problem :-) Christian Graus - Microsoft MVP - C++

                  B 1 Reply Last reply
                  0
                  • C Christian Graus

                    brian55 wrote: "> Good up to this point. You still have multi nested quotes, which means that the value for src is still the value from the first open quote to the first close quote. Your function should check the value in question and return one of the two aspx names accordingly, then your line will be src="<%GetFrameSource()%>" brian55 wrote: Much closer to understanding the bigger picture here.... Glad to hear it, hope this solves the problem :-) Christian Graus - Microsoft MVP - C++

                    B Offline
                    B Offline
                    brian55
                    wrote on last edited by
                    #9

                    OK, NOW I really get..... put the logic in the c# file rather then in the APSX page. I did this and the values are correct. HOWEVER.... the proper page is still not loading. In fact No page is loading. When I right click and try to view the code for that frame I get a blank page. Could this have anything to do with the fact that the compiler complained when I did not put a ; after the method call? When I ran the code like this The compiler complained saying it was expecting ; I put one in ( after the() ), it compiles but I have the above problem. Thanks yet again!

                    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