how to use a variable defined in aspx.cs in an aspx file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kino
    New Member
    • Feb 2011
    • 19

    how to use a variable defined in aspx.cs in an aspx file

    Hello,

    I have a variable in a ".cs.aspx" file and I want to use it in the same page's ".aspx" file, I tried using Reponse.Write with the help of the syntax:

    Code:
    <%Response.Write(var)%>
    But it isn't working, it shows var as unknown. Could anyone please help?
  • NitinSawant
    Contributor
    • Oct 2007
    • 271

    #2
    did u try making the variable public in the code behind file

    Code:
    public string TestVariable="Test";
    Code:
    <%Response.Write(TestVariable)%>

    Comment

    • kino
      New Member
      • Feb 2011
      • 19

      #3
      No, but I used it as a protected string variable and it worked, will this work too?

      Anyway, thanks for the reply!

      Comment

      • NitinSawant
        Contributor
        • Oct 2007
        • 271

        #4
        yes this will work,

        protected also works

        Comment

        Working...