Hello, I have a function that derives a URL in a CMS. I want to call that function from the markup in the EmptyDataText of a gridview control.
But, this won't evaluate...it renders the literally.
<asp:GridView ID="grdRealized" runat="server" AutoGenerateColumns="False"
DataSourceID="sqlRealizedGains"
CellPadding="5"
EmptyDataText="You currently have no sell transactions set up. If you want, you can <a href='<%# GetTranURL() %>'>add one now</a>."
And in the code behind, my function is:
Protected Function GetTranURL()
Dim TranPageURL As MetalQuickController = New MetalQuickController
GetTranURL = TranPageURL.TransactionPageURL
End Function
I am using this property in other code behind pages and it works find, but when I try to call it from the markup, it won't evaluate. I get:
<a href="<%# GetTranURL() %>">add one now</a>
Oh and while I am on the subject, what is the difference between:
Public Function GetTranURL() As String
Dim TranPageURL As MetalQuickController = New MetalQuickController
return TranPageURL.TransactionPageURL
End Function
Please 'Mark as Answer' if my post helped you
--------------------------------------------------
Muhammad Amin
محمد امين
<EmptyDataTemplate>
<%= "You currently have no sell transactions set up. If you want, you can <a href=\"" + GetTranURL() + "\">add one now</a>" %>
</EmptyDataTemplate>
NOTE:- \" is escape sequence in C#. use appropriate for VB
<EmptyDataTemplate>
<%= "You currently have no sell transactions set up. If you want, you can <a href=" + GetTranURL() + ">add one now</a>" %>
</EmptyDataTemplate>
Please 'Mark as Answer' if my post helped you
--------------------------------------------------
Muhammad Amin
محمد امين
Protected Function GetTranURL()
Dim TranPageURL As MetalQuickController = New MetalQuickController
GetTranURL = TranPageURL.TransactionPageURL
End Function
I am using this property in other code behind pages and it works find, but when I try to call it from the markup, it won't evaluate. I get:
<a href="<%# GetTranURL() %>">add one now</a>
Hi,
As far as I know, you cannot call a server method from client side like this. You better do an ajax call.
One more idea is to handle the gridview's DataBound event. In there check if the Rows count is zero; if it is simply set the EmptyDataText value in the code directly. I think that should work.
chadwixk
Member
71 Points
92 Posts
Why won't code in Markup evaluate?
Mar 08, 2012 01:06 AM|LINK
Hello, I have a function that derives a URL in a CMS. I want to call that function from the markup in the EmptyDataText of a gridview control.
But, this won't evaluate...it renders the literally.
<asp:GridView ID="grdRealized" runat="server" AutoGenerateColumns="False" DataSourceID="sqlRealizedGains" CellPadding="5" EmptyDataText="You currently have no sell transactions set up. If you want, you can <a href='<%# GetTranURL() %>'>add one now</a>."And in the code behind, my function is:
Protected Function GetTranURL() Dim TranPageURL As MetalQuickController = New MetalQuickController GetTranURL = TranPageURL.TransactionPageURL End FunctionI am using this property in other code behind pages and it works find, but when I try to call it from the markup, it won't evaluate. I get:
Oh and while I am on the subject, what is the difference between:
<%#
<%$
<%=
Thanks so much in Advance!
Chad
mameenkhn
Contributor
2026 Points
391 Posts
Re: Why won't code in Markup evaluate?
Mar 08, 2012 03:20 AM|LINK
Make GetTranURL public not protected then use below
--------------------------------------------------
Muhammad Amin
محمد امين
chadwixk
Member
71 Points
92 Posts
Re: Why won't code in Markup evaluate?
Mar 08, 2012 03:38 AM|LINK
Thanks mameenkhn, I tried that but that doesn't work either.
I have it the way I posted originally in another user control, and it works fine...any ideas what else would affect this?
mameenkhn
Contributor
2026 Points
391 Posts
Re: Why won't code in Markup evaluate?
Mar 08, 2012 03:56 AM|LINK
Public Function GetTranURL() As String Dim TranPageURL As MetalQuickController = New MetalQuickController return TranPageURL.TransactionPageURL End Function--------------------------------------------------
Muhammad Amin
محمد امين
chadwixk
Member
71 Points
92 Posts
Re: Why won't code in Markup evaluate?
Mar 08, 2012 04:21 AM|LINK
Thanks again, but that didn't work either. Given what is rendering in the html, I don't think it is even getting to call the function.
Very frustrating. Any other ideas?
mameenkhn
Contributor
2026 Points
391 Posts
Re: Why won't code in Markup evaluate?
Mar 08, 2012 04:59 AM|LINK
use GridView EmptyDataTemplate
NOTE:- \" is escape sequence in C#. use appropriate for VB
--------------------------------------------------
Muhammad Amin
محمد امين
ramiramilu
All-Star
95503 Points
14106 Posts
Re: Why won't code in Markup evaluate?
Mar 08, 2012 06:36 AM|LINK
instead of calling directly page method in this way, you can make a call to a javascript routine and in javascript routine call pagemethods using ajax...http://blog.devarchive.net/2007/12/calling-page-methods-from-javascript.html
if you still want to call pagemethods directly in code - http://msdn.microsoft.com/en-us/library/ms178135.aspx
and the difference between inline render blocks - http://support.microsoft.com/kb/976112
http://weblogs.asp.net/ahmedmoosa/archive/2010/10/06/embedded-code-and-inline-server-tags.aspx
Thanks,
JumpStart
Ruchira
All-Star
43050 Points
7036 Posts
MVP
Re: Why won't code in Markup evaluate?
Mar 08, 2012 07:40 AM|LINK
Hi,
As far as I know, you cannot call a server method from client side like this. You better do an ajax call.
My Tech blog | My YouTube ChannelPlease 'Mark as Answer' if this post helps you.Dave Sussman
All-Star
37716 Points
5005 Posts
ASPInsiders
MVP
Re: Why won't code in Markup evaluate?
Mar 08, 2012 08:13 AM|LINK
Yes, the EmptyDataTemplate idea is the way to go. You can't use binding expressions in the EmptyDataText property.
<%# is a data binding expression. When used with Eval or Bind it extracts data from the data source bound to the control (or parent control)
<%$ is an expression builder, used mainly for extracting things like connection strings, resources and routes.
<%= is just a server code block, generally used for inserting values from code behind, such as global variables or method results.
MetalAsp.Net
All-Star
112201 Points
18262 Posts
Moderator
Re: Why won't code in Markup evaluate?
Mar 08, 2012 08:23 AM|LINK
One more idea is to handle the gridview's DataBound event. In there check if the Rows count is zero; if it is simply set the EmptyDataText value in the code directly. I think that should work.