Is possible to use a method in a LinkButton declaration?

  • Thread starter Thread starter Carlos CR
  • Start date Start date
C

Carlos CR

Hello,

If I code this:

[...]
<script language="c#" runat="server">
void Page_Load() {
Page.DataBind();
}

string giveMeAValue() {
string value = "here you have";
return value;
}
string giveMeAValue( aValue ) {
// some logic to determine the value
return value;
}

</script>

[...]

<form runat="server">
<asp:LinkButton CommandName="Sort" CommandArgument="login ASC" Text="<%#
giveMeAValue() %>" runat="server" />
</form>
[...]

It works fine, but if I try to pass a static parameter in the
giveMeAValue method like this:
[...]
<form runat="server">
<asp:LinkButton CommandName="Sort" CommandArgument="login ASC" Text="<%#
giveMeAValue( "aValue" ) %>" runat="server" />
</form>
[...]

It just says it's a malformed server tag.

Is there any way of passing a parameter in the TextField of a
LinkButton?

Thanks

Carlos CR
 
Carlos, try:

<asp:LinkButton CommandName="Sort" CommandArgument="login ASC"
Text='<%# giveMeAValue( "aValue" ) %>' runat="server" />

Note that I changed the " around the value for Text to '

Thank you very much. It works! :)

Regards

Carlos CR
 
Back
Top