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

M

mikepolitowski

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
 
R

Raymond

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.
 
R

Raymond

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top