473,386 Members | 1,819 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,386 software developers and data experts.

Having trouble calling code-behind functions from within an .aspx page

Hi folks,

I am have been trying to solve this problem for quite some time now and
would appreciate any advice. I have been trying to call a code-behind
function that is defined in my aspx.cs from within a DataList
<ItemTemplate> block using the <%# %> syntax. I would not have written
here if I had not spent over 6 hours trying to find a solution to this
problem again any advice is greatly appreciated.

I have included a code snippet below of the HTML code inside my .aspx
page. This code is found between the <ItemTemplate></ItemTemplate>
tags. (I have excluded the rest of the code to reduce spam; if you
need more information please let me know).

<asp:HyperLink ID="imgCovertResult"
NavigateUrl="InterviewQuestions.aspx?catId=<%#
DataBinder.Eval(Container.DataItem, "cat_id") %>"
ImageUrl="<%# GetResultImage(DataBinder.Eval(Container.DataItem,
"cat_id"), DataBinder.Eval(Container.DataItem, "covert_cutpoint_min"))
%>">
</asp:HyperLink>

Here is a small snippet of the .aspx.cs file that is associated with
the page. I have included a header to show class creation and the
function definition that resides within.
namespace Company1.WebUI.Admin
{
/// <summary>
/// Display Report Summaries for general users and display an Invalid
Surveys grid for Admin users
/// </summary>
public class AtRiskCategories :
Company1.WebUI.Admin.UIComponents.PageBase
{

..... more code ....

public string GetResultImage( int cat_id, int covert_cutpoint )
{
string sql;
DataSet ds;
int score;
......more code...
}
When I compile everything I get no compiler erros but when I then go to
the page I get this error msg,

Compiler Error Message: CS0103: The name 'GetResultImage' does not
exist in the current context

If I remove the line <%#
GetResultImage(DataBinder.Eval(Container.DataItem, "cat_id"),
DataBinder.Eval(Container.DataItem, "covert_cutpoint_min")) %> it
works like a charm, but that was expected. (Note: I do properly
populate the DataList with a valid DataSet and the results are correct
when the line above is omitted).

I have tried so hard to figure this out I am just hitting my head
against the wall. I have tried everything I can think of. I have a
book that tells me that it is possible to call a code-behind function
like this within a DataList (and my syntax above is almost exact). Any
advice or suggestions are greatly appreciated. Thank you for reading
this!

Best Regards,

Mike P

Apr 5 '06 #1
2 3519
Looks like an overloading/unboxing issue. It's looking for
a different GetResultImage because of the mismatched
parameters. What if you explicitly convert the Eval
results to int? Unboxing can't be implicit.

<mi************@yahoo.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Hi folks,

I am have been trying to solve this problem for quite some time now and
would appreciate any advice. I have been trying to call a code-behind
function that is defined in my aspx.cs from within a DataList
<ItemTemplate> block using the <%# %> syntax. I would not have written
here if I had not spent over 6 hours trying to find a solution to this
problem again any advice is greatly appreciated.

I have included a code snippet below of the HTML code inside my .aspx
page. This code is found between the <ItemTemplate></ItemTemplate>
tags. (I have excluded the rest of the code to reduce spam; if you
need more information please let me know).

<asp:HyperLink ID="imgCovertResult"
NavigateUrl="InterviewQuestions.aspx?catId=<%#
DataBinder.Eval(Container.DataItem, "cat_id") %>"
ImageUrl="<%# GetResultImage(DataBinder.Eval(Container.DataItem,
"cat_id"), DataBinder.Eval(Container.DataItem, "covert_cutpoint_min"))
%>">
</asp:HyperLink>

Here is a small snippet of the .aspx.cs file that is associated with
the page. I have included a header to show class creation and the
function definition that resides within.
namespace Company1.WebUI.Admin
{
/// <summary>
/// Display Report Summaries for general users and display an Invalid
Surveys grid for Admin users
/// </summary>
public class AtRiskCategories :
Company1.WebUI.Admin.UIComponents.PageBase
{

.... more code ....

public string GetResultImage( int cat_id, int covert_cutpoint )
{
string sql;
DataSet ds;
int score;
.....more code...
}
When I compile everything I get no compiler erros but when I then go to
the page I get this error msg,

Compiler Error Message: CS0103: The name 'GetResultImage' does not
exist in the current context

If I remove the line <%#
GetResultImage(DataBinder.Eval(Container.DataItem, "cat_id"),
DataBinder.Eval(Container.DataItem, "covert_cutpoint_min")) %> it
works like a charm, but that was expected. (Note: I do properly
populate the DataList with a valid DataSet and the results are correct
when the line above is omitted).

I have tried so hard to figure this out I am just hitting my head
against the wall. I have tried everything I can think of. I have a
book that tells me that it is possible to call a code-behind function
like this within a DataList (and my syntax above is almost exact). Any
advice or suggestions are greatly appreciated. Thank you for reading
this!

Best Regards,

Mike P

Apr 6 '06 #2
Although I'm puzzled why you're not getting an
overload error instead. So looks like even
before it gets to that it's not seeing any GetResultImage.
Are you sure the Inherts on the page is set to the
namespace and class of the codebehind?
And if there is an src in the page directive, try
removing it.

Does it work if you move the method out of the
code-behind into the page itself, in a server-side
script block?
<mi************@yahoo.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Hi folks,

I am have been trying to solve this problem for quite some time now and
would appreciate any advice. I have been trying to call a code-behind
function that is defined in my aspx.cs from within a DataList
<ItemTemplate> block using the <%# %> syntax. I would not have written
here if I had not spent over 6 hours trying to find a solution to this
problem again any advice is greatly appreciated.

I have included a code snippet below of the HTML code inside my .aspx
page. This code is found between the <ItemTemplate></ItemTemplate>
tags. (I have excluded the rest of the code to reduce spam; if you
need more information please let me know).

<asp:HyperLink ID="imgCovertResult"
NavigateUrl="InterviewQuestions.aspx?catId=<%#
DataBinder.Eval(Container.DataItem, "cat_id") %>"
ImageUrl="<%# GetResultImage(DataBinder.Eval(Container.DataItem,
"cat_id"), DataBinder.Eval(Container.DataItem, "covert_cutpoint_min"))
%>">
</asp:HyperLink>

Here is a small snippet of the .aspx.cs file that is associated with
the page. I have included a header to show class creation and the
function definition that resides within.
namespace Company1.WebUI.Admin
{
/// <summary>
/// Display Report Summaries for general users and display an Invalid
Surveys grid for Admin users
/// </summary>
public class AtRiskCategories :
Company1.WebUI.Admin.UIComponents.PageBase
{

.... more code ....

public string GetResultImage( int cat_id, int covert_cutpoint )
{
string sql;
DataSet ds;
int score;
.....more code...
}
When I compile everything I get no compiler erros but when I then go to
the page I get this error msg,

Compiler Error Message: CS0103: The name 'GetResultImage' does not
exist in the current context

If I remove the line <%#
GetResultImage(DataBinder.Eval(Container.DataItem, "cat_id"),
DataBinder.Eval(Container.DataItem, "covert_cutpoint_min")) %> it
works like a charm, but that was expected. (Note: I do properly
populate the DataList with a valid DataSet and the results are correct
when the line above is omitted).

I have tried so hard to figure this out I am just hitting my head
against the wall. I have tried everything I can think of. I have a
book that tells me that it is possible to call a code-behind function
like this within a DataList (and my syntax above is almost exact). Any
advice or suggestions are greatly appreciated. Thank you for reading
this!

Best Regards,

Mike P

Apr 6 '06 #3

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

Similar topics

1
by: Anand | last post by:
Hi i am having trouble adding a recordset into the access database, the code seems to be working fine it passs and parses through all variables just fine without showing any errors and also when i...
10
by: Alejandro Castañaza | last post by:
Hi. I'm writing a program, and I need to send confidential data through the network, so I decided to use encryption, using the System.Security.Cryptography namespace. I'm using the sockets...
7
by: Andrew Christiansen | last post by:
Hey everyone. I have Visual Basic .NET 2003 and am trying to show images on a treeview control. I have the imagelist on the form filled with images, and have the ImageList property of the...
8
by: Flack | last post by:
Hey guys, In my app I have a bitmap where drawing is done and in the form's paint method I show the bitmap: private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {...
5
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL=...
0
by: sachins5 | last post by:
Hi everyone, I am facing a problem here... my build was working fine till yesterday and then out of the blue every debug operation resulted in An unhandled exception of type occured in the...
2
by: Stu | last post by:
Hi guys, I've been having trouble getting the clock function to work portably, please could I get some thoughts? <Possibly OT comments> It works fine on my laptop (under WinXP) and on my...
5
by: polas | last post by:
Afternoon everyone. I am having some trouble and thought a few of you might be able to help me... I have a simple function to copy the contents of one array into another - the arguments to the...
0
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
3
by: Howard Swope | last post by:
Greetings: C++ CLR .Net 2 I have a ref class that I have created that wraps an unmanaged pointer. It acts like a smart pointer for reference counted objects for a particular library I am...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.