473,508 Members | 3,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.Net / C# / Visual Studio.Net Accessing Code Behind Methods and Properties from the Designer

I'm getting my feet wet learning C# and .net from a VBScript
background. I have built a small application that uses custom 'info'
objects, each of which contains a single record from a SQL database. I
have bound an array of these objects to a datagrid and have been
trying to work within the limited confines of the built-in ASP.net
Datagrid control. When speaking with a colleague who has a C++
background he suggested that I create my own grid control. I've been
trying to do this by putting all the code that dimensions the array
and populates it into my codebehind and simply creating a 'for' loop
in my HTML code with a reference to each object in the array in html
table cells within the loop. My problem is I can't seem to access the
array object defined in the codebehind in the C# embedded in my HTML
code, I'm guessing that the line at the top of the page:

'<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="RequestsGrid.ascx.cs"
Inherits="DTS_UI.Components.requestgrid"%>'

is supposed to take care of this but that doesn't seem to be the case.
Can anyone point out what I'm missing?

Luminousc
Nov 19 '05 #1
4 1534
OK, I worked out that my array object needed to be set to public or
protected in order to be able to see it in the designer. Got that,
great. However I now have this strange issue:

<%for (int xx=0; xx<=myInfoRequestArr.Length; xx++){%>
<tr style="FONT-SIZE:smaller; ForeColor:Black; BackColor:#FFA0A0">
<td Style="FONT-SIZE:7pt; WIDTH:23px; HorizontalAlign:Left">
<%# myInfoRequestArr[xx].RequestID.ToString() %>
</td>
</tr>
<%}%>

When I try and run this I get:
" CS0103: The name 'xx' does not exist in the class or namespace
'ASP.RequestsGrid_ascx' "

Why can't the second code-block see the xx integer variable from the
first?!?!

Luminousc

Nov 19 '05 #2
The data binding expressions (inside of <%# %>) are put into a
different scope when code is generated for this aspx page, and this
code will execute when you call DataBind on the page.

If you want a finer grain of control over the output without having to
write all the looping code, etc., I'd suggest trying the asp.net
Reapeater control.

Here is some more info on what happens with data binding expressions:

http://odetocode.com/Articles/278.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/
On 3 Mar 2005 04:09:26 -0800, lu*******@yahoo.com wrote:
OK, I worked out that my array object needed to be set to public or
protected in order to be able to see it in the designer. Got that,
great. However I now have this strange issue:

<%for (int xx=0; xx<=myInfoRequestArr.Length; xx++){%>
<tr style="FONT-SIZE:smaller; ForeColor:Black; BackColor:#FFA0A0">
<td Style="FONT-SIZE:7pt; WIDTH:23px; HorizontalAlign:Left">
<%# myInfoRequestArr[xx].RequestID.ToString() %>
</td>
</tr>
<%}%>

When I try and run this I get:
" CS0103: The name 'xx' does not exist in the class or namespace
'ASP.RequestsGrid_ascx' "

Why can't the second code-block see the xx integer variable from the
first?!?!

Luminousc


Nov 19 '05 #3
<%# myInfoRequestArr[xx].RequestID.ToString() %>

needs to change to

<%= myInfoRequestArr[xx].RequestID.ToString() %>

also you'll need to change your for statement to be:

for (int xx=0; xx<myInfoRequestArr.Length; xx++){

(notice how it' sjust less than (<) vs less than or equal (<=)

<%# is used for databinding and isn't evaluated at the same time as <%
which is why xx isn't declared
You do know that ASP.Net offers databound controls which make this type of
code bad, right?

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<lu*******@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
OK, I worked out that my array object needed to be set to public or
protected in order to be able to see it in the designer. Got that,
great. However I now have this strange issue:

<%for (int xx=0; xx<=myInfoRequestArr.Length; xx++){%>
<tr style="FONT-SIZE:smaller; ForeColor:Black; BackColor:#FFA0A0">
<td Style="FONT-SIZE:7pt; WIDTH:23px; HorizontalAlign:Left">
<%# myInfoRequestArr[xx].RequestID.ToString() %>
</td>
</tr>
<%}%>

When I try and run this I get:
" CS0103: The name 'xx' does not exist in the class or namespace
'ASP.RequestsGrid_ascx' "

Why can't the second code-block see the xx integer variable from the
first?!?!

Luminousc

Nov 19 '05 #4
Thanks guys, I have been playing with the built-in DataGrids, DataList
and the Repeater, My actual page is very much more complicated than my
example, I just simplified it down to the basics so as to make my query
easier to read. Switching to '=' instead of the '#' I've seen in all
the other examples I've so-far seen has fixed the problem.

Thanks very much

Luminousc

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2291
by: Dotnetified | last post by:
Reposting after about 2 weeks of no response ... thanks if you can help... ---------------------------------------------------------------------------- -------------- To anyone who thinks they...
33
3092
by: John Timbers | last post by:
I'd like to purchase Visual C# .Net for learning purposes only since it's a lot cheaper than Visual Studio (note that I'm a very experienced C++ developer). Can someone simply clarify the basic...
4
1777
by: Steve Richter | last post by:
using visual studio 2003 for my asp.net projects ... Once I undock the property window to get a better look at things, I cant dock it back where it came from. Can someone tell me how to redock...
2
1334
by: Nick Stansbury | last post by:
Hi, I'm not sure where to post this - but I'll try here. I'm encountering some really weird behaviour in visual studio and I can't work out where it is coming from. In various files,...
2
1302
by: Axel Dahmen | last post by:
Hi, after I've added a property to my web page I can't open it in Visual Studio Designer anymore. I get the error message "File couldn't be opened in Web Forms Designer. enablesessionstate page...
3
4768
by: xycos | last post by:
Hello. I apologize for asking this question as the information I need is availible via the MSDN library, however I cannot seemt o understand what I need to do, so I'm asking here. I have created...
8
6253
by: WT | last post by:
Is it normal that Visual Studio sets the PreInit handler for a Page from the OnInit code ? No chance to fire it as OnPreInit is run befor OnInit. ??? CS
0
941
by: Nathan Sokalski | last post by:
When Visual Studio 2005 generates the *.designer.vb files for my *.aspx and *.ascx files, it is including the following before each control declaration: '''<summary> '''Label1 control....
4
2625
by: Goran Djuranovic | last post by:
Hi all, I am experiencing a strange thing happening with a "designer.vb" page. Controls I manually declare in this page are automatically deleted after I drop another control on a ".aspx" page. -...
0
7228
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
7128
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...
0
7393
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...
1
7058
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...
0
7502
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...
0
5635
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,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1565
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 ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.