Solved

accessing a code behind variable from aspx

Posted on 2006-07-20
6
245 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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