ASP.net variable assignment

Discussion in 'ASP .Net' started by vincenthkh@gmail.com, Jan 31, 2007.

  1. Guest

    I am new in ASP.net programming (but have ASP skill) and have some
    problems.

    I have a ASPX page. First I declare the variable, then I want to
    include the different values to the variable based on some conditions
    of temp1 session. Then display the value on the label. Code like this:

    <script language="vb" runat=server>
    Dim var1 as string = "aaa"
    .........
    </script>

    <% if session("temp1")="1" then %>
    <!--#include file="Value1.aspx"-->
    <% else %>
    <!--#include file="Value2.aspx"-->
    <% end %>

    <script language="vb" runat="server">
    Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs)
    lblMsg.Text = "var1: " & var1
    End Sub
    </script>

    ...............

    In Value1.aspx, I assign var1 as "bbb"
    <% var1 = "bbb" %>

    And in Value2.aspx, I assign var1 as "ccc"
    <% var1 = "ccc" %>

    However, the code between <%... %> seems not assigned the value. And
    always display "aaa".

    Do anyone can tell me what is the problem and how I can change? Thanks.
     
    , Jan 31, 2007
    #1
    1. Advertising

  2. Mike Chen Guest

    asp.net is quite different from asp.
    Because asp is running on the way of interpreting while asp.net is a
    compiled language. You mixed the server-side code and client-side together
    and ignored the life cycle of asp.net page.

    You can read the content of files and assign the strings to "var1 " variant
    in your code. like:
    <% if session("temp1")="1" then
    var1 = File.ReadAllText("Value1.aspx")
    else
    var1 = File.ReadAllText("Value2.aspx")
    end %>

    --
    Sincerely,
    Mike Chen
    http://chagel.com


    <> wrote in message
    news:...
    >I am new in ASP.net programming (but have ASP skill) and have some
    > problems.
    >
    > I have a ASPX page. First I declare the variable, then I want to
    > include the different values to the variable based on some conditions
    > of temp1 session. Then display the value on the label. Code like this:
    >
    > <script language="vb" runat=server>
    > Dim var1 as string = "aaa"
    > ........
    > </script>
    >
    > <% if session("temp1")="1" then %>
    > <!--#include file="Value1.aspx"-->
    > <% else %>
    > <!--#include file="Value2.aspx"-->
    > <% end %>
    >
    > <script language="vb" runat="server">
    > Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs)
    > lblMsg.Text = "var1: " & var1
    > End Sub
    > </script>
    >
    > ..............
    >
    > In Value1.aspx, I assign var1 as "bbb"
    > <% var1 = "bbb" %>
    >
    > And in Value2.aspx, I assign var1 as "ccc"
    > <% var1 = "ccc" %>
    >
    > However, the code between <%... %> seems not assigned the value. And
    > always display "aaa".
    >
    > Do anyone can tell me what is the problem and how I can change? Thanks.
    >
     
    Mike Chen, Jan 31, 2007
    #2
    1. Advertising

  3. bruce barker Guest

    unlike asp, aspx does not have a <!-#include> statment. its just a
    comment, and has no impact on your code.
    because asp.net is compiled, it doesn't have conditional includes.

    -- bruce (sqlwork.com)


    wrote:
    > I am new in ASP.net programming (but have ASP skill) and have some
    > problems.
    >
    > I have a ASPX page. First I declare the variable, then I want to
    > include the different values to the variable based on some conditions
    > of temp1 session. Then display the value on the label. Code like this:
    >
    > <script language="vb" runat=server>
    > Dim var1 as string = "aaa"
    > ........
    > </script>
    >
    > <% if session("temp1")="1" then %>
    > <!--#include file="Value1.aspx"-->
    > <% else %>
    > <!--#include file="Value2.aspx"-->
    > <% end %>
    >
    > <script language="vb" runat="server">
    > Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs)
    > lblMsg.Text = "var1: " & var1
    > End Sub
    > </script>
    >
    > ..............
    >
    > In Value1.aspx, I assign var1 as "bbb"
    > <% var1 = "bbb" %>
    >
    > And in Value2.aspx, I assign var1 as "ccc"
    > <% var1 = "ccc" %>
    >
    > However, the code between <%... %> seems not assigned the value. And
    > always display "aaa".
    >
    > Do anyone can tell me what is the problem and how I can change? Thanks.
    >
     
    bruce barker, Jan 31, 2007
    #3
  4. Guest

    But now, even I replace as no include file and assign the value in
    this page. It still always "aaa". Why?
    <% if session("temp1")="1" then
    var1 = "bbb"
    else
    var1 = "ccc"
    end %>

    Also File.ReadAllText returns the text string of the file, but I want
    to include file with code. Then how to do if asp.net doesn't have <!--
    #include> statement?

    Thanks.

    -- Vincent
     
    , Feb 2, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. nagy
    Replies:
    36
    Views:
    1,023
    Terry Reedy
    Jul 20, 2006
  2. Chris
    Replies:
    34
    Views:
    1,551
  3. mfglinux
    Replies:
    11
    Views:
    724
    Roberto Bonvallet
    Sep 12, 2007
  4. David Filmer
    Replies:
    19
    Views:
    256
    Kevin Collins
    May 21, 2004
  5. Derek Basch
    Replies:
    8
    Views:
    140
    Ben Morrow
    Aug 12, 2006
Loading...

Share This Page