473,395 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ASP / C# Code Behind variable reference problem

I've got a question for the gurus out there.

I'm trying to create an IF conditional inside my aspx page that reads the state of a boolean in the code behind.

Here's the basic ASP:

Expand|Select|Wrap|Line Numbers
  1. <asp:Repeater ... OnItemDataBound="PrepareRepeater">
  2.  
  3.     <ItemTemplate>
  4.  
  5.         // some code
  6.  
  7.         <#if (variableName == true) {#>
  8.  
  9.             // code I want to conditionally control
  10.  
  11.         <#}#>
  12.  
  13.     </ItemTemplate
  14.  
  15. </asp:Repeater>
The code behind looks something like this:

Expand|Select|Wrap|Line Numbers
  1. bool variableName; // global
  2.  
  3. public void PrepareRepeater() {
  4.  
  5.     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
  6.  
  7.         if (//something) {
  8.             variableName = true;
  9.         } else {
  10.             variableName = false;
  11.         }
  12.  
  13.     }
  14.  
  15. }
Now, my problem is that when I try to read the value of "variableName" on the ASP page it never gives me the current value. It seems to me that, since the ASP "<% if %>" conditional is in the ItemTemplate that it should be reading the current value of "variableName."

Instead it acts like it waits to check the value after all the OnItemDataBound events have ocurred. Maybe this is simple but I can't figure out how to read the value of "variableName" during the OnItemDataBound event.

If anyone can help I'd greatly appreciate it.
Sep 11 '08 #1
1 1599
DrBunchman
979 Expert 512MB
Hi beardog,

Welcome to Bytes.com! I hope you find the site useful.

You've posted your question in the ASP Forum which is for Classic ASP only - I've moved it for you but in future please post all ASP.NET questions in the .NET Forum.

Hopefully you'll find a solution to your problem in there :-)

Dr B
Sep 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

40
by: Neo The One | last post by:
I think C# is forcing us to write more code by enforcing a rule that can be summarized as 'A local variable must be assgined *explicitly* before reading its value.' If you are interested in what...
4
by: Mark Friedman | last post by:
I can't seem to figure out how to get a reference to a UserControl in the code-behind for the page that contains the control. All the examples I've seen show how to pass property values from the...
5
by: Dan | last post by:
We have a simple site. It's a frameset with two frames a left and a right. The left frame is essentially a list of records from a database (using a server-side repeater control). When you click...
6
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
5
by: GaryB | last post by:
The following line of code works fine in my code-behind file for an aspx page: Dim HeadingRow As DataRow = dsGridReport.Tables(0).NewRow() But when I transport that same code to a class and...
2
by: Kurt Schroeder | last post by:
Still new to code behind so i'm not sure what the problem is (i'm using visualStudio.net for the first time) like my last question i'll bet this has a quick answer. thanks kes here is the error:...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
3
by: aaa | last post by:
I fail to see the connection between the code behind and the raw HTML of the ASPX page how do you get variables and functions to communicate with each other? I cannot get this to even fire:...
2
by: Anthony Bollinger | last post by:
I am still getting up to speed with ASP.NET 2.0 and its companions (VS, VB, etc.). I am successfully using a PagedDataSource in my code-behind module, but I need to reference the PageCount on the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.