Declare variable in Codebehind and display it in the HTML form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    Declare variable in Codebehind and display it in the HTML form

    Hi there,

    In classic asp(using vb) I can declare variables like this.

    [CODE=asp] <%
    Dim var1 as string ="My Var Value"
    %>
    [/CODE]

    And Some Where in my asp page I can print it.Like this,
    [CODE=asp]<%=var1%>[/CODE]

    Correct ?

    How can I do the same thing in ASP.NET(1.1).Wh at i need really I need to Declare the var1 at the codbehind and need to print it in a HTML Form element

    Thanks!
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    Originally posted by ajaxrand
    Hi there,

    In classic asp(using vb) I can declare variables like this.

    [CODE=asp] <%
    Dim var1 as string ="My Var Value"
    %>
    [/CODE]

    And Some Where in my asp page I can print it.Like this,
    [CODE=asp]<%=var1%>[/CODE]

    Correct ?

    How can I do the same thing in ASP.NET(1.1).Wh at i need really I need to Declare the var1 at the codbehind and need to print it in a HTML Form element

    Thanks!
    moved to .NET forum

    Jared

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      I am fairly certain those types of constructs are still valid.
      If you declared a variable in the code behind section called: MyInt

      Then in your aspx page you could put like:
      [code=aspx]
      MyInt has the value of <%=MyInt.ToStri ng() %>
      [/code]

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by Plater
        I am fairly certain those types of constructs are still valid.
        If you declared a variable in the code behind section called: MyInt

        Then in your aspx page you could put like:
        [code=aspx]
        MyInt has the value of <%=MyInt.ToStri ng() %>
        [/code]
        Plater is right, this will work perfectly fine :)

        You have to make sure that you declare your variable as a Public Integer though or else it will not be accessible.

        -Frinny

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          Thank you Plater.
          Thank you Frinavale.

          It really helped to me.
          -Ajaxrand

          Comment

          Working...