Hi,
Is it possible to call a class's static property to set the navigateurl property?
<asp:HyperLink ID="hlRegister" NavigateUrl="<%= SomeClass.Property %>" runat="server" />
without using codebehind ofcourse!
Hi,
Is it possible to call a class's static property to set the navigateurl property?
<asp:HyperLink ID="hlRegister" NavigateUrl="<%= SomeClass.Property %>" runat="server" />
without using codebehind ofcourse!
sure, in the code behind:
hl.NavigateUrl = Class.Static().ToString();
You don't need code behind. You can just try it, like i just did. I created a simple page with exactly the code you have, and then created a class called SomeClass with a property named Property. It worked fine for me the way that you have it set up above.
Edit: Ok, it didn't compile with an error.. but It's giving me not the result I'm looking for.
http://localhost:3061/Sample/%3C%=%20SomeClass.Property.ToString()%20%%3E
using:
public static class SomeClass
{
public static string Property
{
get { return "http://www.google.com"; }
}
}
and
<asp:HyperLink ID="hlRegister" NavigateUrl='<%= SomeClass.Property.ToString() %>' Text="Goooooogle" runat="server" />
You can do this, but to avoid a syntax error you must modify your example to be as follows.
<asp:HyperLink ID="hlRegister"
NavigateUrl='<%= SomeClass.Property %>' runat="server" />
Notice the small difference of using single quotes rather than double around the script.
However, one might really ask why not just do it in the codebehind.