Solved

accessing a code behind variable from aspx

Posted on 2006-07-20
6
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 125 total points
ID: 17152429
for the problem you mentioned in above = is the correct solution ......
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…

733 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