views:

30

answers:

2

I have implemented a helper extension method on an interface that my Master page implements called "Url" to create URLs using business logic.

This allows me to do this on my Master markup...

<a href="<%=this.Url("/mypage.aspx", forceHttps: true)%>">Click Me Secure</a>
<a href="<%=this.Url("/mypage.aspx")%>">Click Me Not Secure</a>

As you can infer from the above, I have an argument on the Url method called "forceHttps" that uses a default value.

This works great on the Master page.

The problem I am having is that pages that use the Master are showing validation errors stating that the Url method does not have an overload with 1 arguments.

Is there a way around this ?

EDIT: This is a non-issue. It turns out that there was a Virtual Directory under the parent site in IIS that was causing the problem...not sure why. Once I removed it, the problem went away.

A: 

Is it problematic to add a single argument overload? That seems like the simplest solution.

Edit: I'm unable to replicate the original problem. After testing, my local dev environment does not throw any validation errors for the above scenario. My test code is below.

MasterPage.master.cs:

public string CreateAlert(string text, string text2 = "default)
{
    return "<script type=\"text/javascript\">alert('" +
            text + ":" + text2 + "');</script>";
}

MasterPage.master:

<%= this.CreateAlert("foo") %>
<%= this.CreateAlert("foo", "bar") %>

This produces two alerts and no validation errors on any page that uses MasterPage, "foo:default" and then "foo:bar".

jball
Simple enough when I have one method, but what about when I have 30 helper methods with various options? Default arguments were designed to remove the necessity of method overloads. I would expect ASP.NET to recognize this new C# construct.
Matthew
The validation error occurs on any page that uses the Master, regardless of usage.
Matthew
A: 

Move Url method to some helper class and reference it with full name (ie. containing namespaces).

BTW: asp.net markup editor is showing errors in Error panel many times, but project can be built and runs ok.

Tomas Voracek