By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,925 Members | 732 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,925 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.