473,666 Members | 2,157 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="Req uestsGrid.ascx. cs"
Inherits="DTS_U I.Components.re questgrid"%>'

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 1542
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<=myInfoReque stArr.Length; xx++){%>
<tr style="FONT-SIZE:smaller; ForeColor:Black ; BackColor:#FFA0 A0">
<td Style="FONT-SIZE:7pt; WIDTH:23px; HorizontalAlign :Left">
<%# myInfoRequestAr r[xx].RequestID.ToSt ring() %>
</td>
</tr>
<%}%>

When I try and run this I get:
" CS0103: The name 'xx' does not exist in the class or namespace
'ASP.RequestsGr id_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<=myInfoReque stArr.Length; xx++){%>
<tr style="FONT-SIZE:smaller; ForeColor:Black ; BackColor:#FFA0 A0">
<td Style="FONT-SIZE:7pt; WIDTH:23px; HorizontalAlign :Left">
<%# myInfoRequestAr r[xx].RequestID.ToSt ring() %>
</td>
</tr>
<%}%>

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

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

Luminousc


Nov 19 '05 #3
<%# myInfoRequestAr r[xx].RequestID.ToSt ring() %>

needs to change to

<%= myInfoRequestAr r[xx].RequestID.ToSt ring() %>

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

for (int xx=0; xx<myInfoReques tArr.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*******@yaho o.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.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<=myInfoReque stArr.Length; xx++){%>
<tr style="FONT-SIZE:smaller; ForeColor:Black ; BackColor:#FFA0 A0">
<td Style="FONT-SIZE:7pt; WIDTH:23px; HorizontalAlign :Left">
<%# myInfoRequestAr r[xx].RequestID.ToSt ring() %>
</td>
</tr>
<%}%>

When I try and run this I get:
" CS0103: The name 'xx' does not exist in the class or namespace
'ASP.RequestsGr id_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
2306
by: Dotnetified | last post by:
Reposting after about 2 weeks of no response ... thanks if you can help... ---------------------------------------------------------------------------- -------------- To anyone who thinks they know it all: ;) We recently upgraded our MSDN Version of VS.NET 2002 to VS.NET 2003... Things are all working well, except we've run across a new bug or issue since our adopting of the new package.
33
3140
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 differences. Ok, Visual Studio has C++, VB and J++ thrown in plus some extra bells and whistles (I already have some minimal experience) but are both IDE's essentially the same (including the same IDE support for creating forms, ADO.NET DataSets,...
4
1785
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 the property window? When I copy HTML snippets from another page the code behind class is not automatically updated with the new controls. For example, the Web Controls are not added to the group of stmts at the start of the page class which...
2
1344
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, seemingly at random, the compiler seems to "forget" about references declared in the code behind file. So when I build I get a whole string of errors like "dgdSearchResults is not defined", but if I right click -> goto definition it goes straight to the...
2
1309
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 directive required to use Session object." I see that Visual Studio Web Forms Designer seems to execute any Property code when opening the page. But I don't want it to.
3
4787
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 application settings in Visual Studio (right-click on the project, go to the settings tab, etc.) and have associated each of these settings with a property on a form. This seems to be working right (i.e. if I edit the default value of a setting,...
8
6263
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
943
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. '''</summary> '''<remarks> '''Auto-generated field. '''To modify move field declaration from designer file to code-behind file.
4
2642
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. - Why is this happening? - Can I disable automatic declaration and have everything be declared manually? - Any other options to fix this? Thanks in advance. Goran Djuranovic
0
8878
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8560
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8644
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6200
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5671
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4200
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2776
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
2
2012
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.