Solved

accessing a code behind variable from aspx

Posted on 2006-07-20
6
239 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 125 total points
ID: 17152429
for the problem you mentioned in above = is the correct solution ......
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Web Form Variables being reset 2 26
Runtime Exceptions when trying to submit data 28 37
Displaying a web form as a modal popup dialog box. 4 25
Message not shown 5 34
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 …
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now