?
Solved

accessing a code behind variable from aspx

Posted on 2006-07-20
6
Medium Priority
?
275 Views
Last Modified: 2010-05-18
hi experts, the below is trivial but it is driving me nuts!
for simplicity i am addressing my problem like this, i am doing the following code in the code behind:

public string x = "L";
      
            private void Page_Load(object sender, System.EventArgs e)
            {
                  if (!IsPostBack)
                  {                        
                        x = "ss";
                                          }
                  else
                  {
                        x = "ddd";
                                          }                  
            }

and am trying to access variable x from the aspx like this:
<td><%# x %></td>
my actual goal is to have more complex coding but have reduced my approach to first accessing x in its simples form.  just that i haev tried this on 2 different webforms now and am getting an empty string.  on other webforms i have used far more complex similar functionality and either i am missing some webform setting or else some magic is determining that this does not work, the end result is that i am going crazy. your help would be apprecaited. 10x a lot.
0
Comment
Question by:stephen_rota
  • 4
  • 2
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 17152017
<td><%= x %></td>

try this

0
 

Author Comment

by:stephen_rota
ID: 17152391
it works great 10x, I have worked wonders with # but always giving hassles until it works, once it works all is fine. do you know fo any issues? is = the correct syntax to say 'evaluate'? i will use the = to concatenate strings inside a javascript open window and so forth.
0
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 375 total points
ID: 17152429
for the problem you mentioned in above = is the correct solution ......
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:stephen_rota
ID: 17152661
10x.
but it does not work when i try to access a string from the code behind named switchInfoImageOpen like this:
<IMG id="SwitchInfoImage" runat="server" height="200" width="200" onclick="openImage('<%= switchInfoImageOpen %>')">
0
 

Author Comment

by:stephen_rota
ID: 17152684
i get
onclick="openImage('<%= switchInfoImageOpen %>')" />
for the last part
0
 

Author Comment

by:stephen_rota
ID: 17152924
solved: it just happens (correct me if i am wrong) that you cannot put a runat=server if you want an evaluation within the tag, so i removed runat=server and it worked fine. 10x for the good tip pratima mcs
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question