Reputation: 2667
I wish to do the following but it doesn't seem possible, was wondering if there is a work around or a way to make it work.
<asp:RequiredFieldValidator ID="rfvImCool"
runat="server"
ErrorMessage="Some error message <%=//Do something here %>"
</asp:RequiredFieldValidator>
You can see I am using the <%= %>
sign in the ErrorMessage parameter.
Upvotes: 2
Views: 84
Reputation: 74919
You can't use <%= %>
but you can use the databinding expression <%# %>
like this:
<asp:RequiredFieldValidator ID="rfvImCool"
runat="server"
ErrorMessage="Some error message <%# SomePropertyOrEvalCall %>"
</asp:RequiredFieldValidator>
The contents of <%# %>
will get called when the control's DataBind
method is called (typically you would call this on the Page
and it would propagate down to the child controls.
Upvotes: 3
Reputation: 499132
Since <%=%>
is short for:
<script runat="server">
Response.Write();
</script>
You should be able to see why you can't use them within a server side control.
You should set the property in the code-behind page:
rfvImCool.ErrorMessage = "Some error message " + " Do something here";
Upvotes: 6