473,581 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP / C# Code Behind variable reference problem

1 New Member
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 "variableNa me" 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 "variableNa me."

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 "variableNa me" during the OnItemDataBound event.

If anyone can help I'd greatly appreciate it.
Sep 11 '08 #1
1 1608
DrBunchman
979 Recognized Expert Contributor
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
3024
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 I mean, please look at this feedback my me: ...
4
7960
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 containing page's HTML to the UserControl but nothing I've seen shows how to reference the UserControl's properties (or subcontrols) from the...
5
2415
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 on one of the items in the left frame, it targets the right frame and displays a form prefilled with information for the item you clicked. The...
6
535
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 web control just fine and script with it as needed from the webform1.aspx page itself just fine, like this: <%@ Page language="c#"...
5
1241
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 run it I get "Object reference not set to an instance of an object" Why?
2
1352
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: and please for give the excessive text Object reference not set to an instance of an object. Description: An unhandled exception occurred during...
171
7674
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) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little...
3
1444
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: <script Language=C# runat=Server> public int myfunc() { int blah = 1;
2
1793
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 page itself to generate links for the pages. I have tried a few things, but I am still limited to old-style (one file) thinking. How can I do this...
0
7862
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7789
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7894
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8169
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6551
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3803
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3820
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1132
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.