Solved

accessing a code behind variable from aspx

Posted on 2006-07-20
6
228 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
Comment Utility
<td><%= x %></td>

try this

0
 

Author Comment

by:stephen_rota
Comment Utility
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
Comment Utility
for the problem you mentioned in above = is the correct solution ......
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:stephen_rota
Comment Utility
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
Comment Utility
i get
onclick="openImage('<%= switchInfoImageOpen %>')" />
for the last part
0
 

Author Comment

by:stephen_rota
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

15 Experts available now in Live!

Get 1:1 Help Now