473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

ASP.net variable assignment

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 '07 #1
3 1496
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
<vi********@gmail.comwrote in message
news:11*********************@l53g2000cwa.googlegro 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.

Jan 31 '07 #2
unlike asp, aspx does not have a <!-#includestatment. 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)
vi********@gmail.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.
Jan 31 '07 #3
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 <!--
#includestatement?

Thanks.

-- Vincent

Feb 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
15
by: Robert Sturzenegger | last post by:
// Code sequence A for (int i = 0; i < 10; ++i) { int k = something(); // some more code which uses k } // Code sequence B int k; for (int i = 0; i < 10; ++i) { k = something();
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
9
by: NevilleDNZ | last post by:
Can anyone explain why "begin B: 123" prints, but 456 doesn't? $ /usr/bin/python2.3 x1x2.py begin A: Pre B: 123 456 begin B: 123 Traceback (most recent call last): File "x1x2.py", line 13,...
4
by: Ray | last post by:
Hello, I think I've had JavaScript variable scope figured out, can you please see if I've got it correctly? * Variables can be local or global * When a variable is declared outside any...
4
by: siddhu | last post by:
If there is reference member variable in the class, why doesn't default assignment operator work? class A { int& i; public: A( int& ii):i(ii){} //A& operator=(const A& a){i = a.i;} };
1
by: globalrev | last post by:
http://mail.python.org/pipermail/python-list/2003-October/233435.html why isnt it printing a in the second(second here, last one in OP) example before complaining? def run(): a = 1 def...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.