Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.net variable assignment

Reply
Thread Tools

ASP.net variable assignment

 
 
vincenthkh@gmail.com
Guest
Posts: n/a
 
      01-31-2007
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.

 
Reply With Quote
 
 
 
 
Mike Chen
Guest
Posts: n/a
 
      01-31-2007
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: ups.com...
>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.
>



 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      01-31-2007
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.
>

 
Reply With Quote
 
vincenthkh@gmail.com
Guest
Posts: n/a
 
      02-02-2007
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
Assignment operator self-assignment check Chris C++ 34 09-26-2006 04:26 AM
Implicit iterator variable $_ changing to ### upon variable assignment? Derek Basch Perl Misc 8 08-12-2006 06:30 PM
Augument assignment versus regular assignment nagy Python 36 07-20-2006 07:24 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57