views:

558

answers:

4

I have the following code in one of my aspx pages:

<% foreach (Dependency dep in this.Common.GetDependencies(this.Request.QueryString["Name"]))
   { %>
        <ctl:DependencyEditor DependencyKey='<%= dep.Key %>' runat="server" />
<% } %>

When I run it, I get the following error:

Parser Error Message: Cannot create an object of type 'System.Guid' from its string representation '<%= dep.Key %>' for the 'DependencyKey' property.

Is there any way that I can create a control and pass in a Guid in the aspx page? I'd really hate to have to loop through and create these controls in the code behind just because of that...

NOTE: The Key property on the Dependency object is a Guid.

+1  A: 

The key property of the Dependency object may be a Guid, but is the DependencyKey Property of the DependencyEditor a Guid too? If not it should be, otherwise the correct TypeConverter won't be invoked upon assignment.

If I'm not mistaken, you could also use dep.Key.ToString() also.

steve_c
Yes the DependencyKey property is a Guid also.
Max Schmeling
Are you using MVC? The reason I think this is happening is because you are using the %= syntax, which always tries to outout a string. If you aren't using MVC, use a Repeater, which will allow you to use the %# syntax. This will perform the correct type conversion on data binding.
steve_c
A: 

is your control taking the value and assuming its a GUID? Have you tried instantiating a GUID with the value? Looks like this is a cast problem

scootdawg
It assumes it's a GUID... and it is...
Max Schmeling
+1  A: 

ok, here's the deal...try using the # symbol instead of the = symbol. I replicated your problem and that gets past the compile issue.

It should look like this "<%# dep.Key %>"

good luck!

scootdawg
A: 

Assuming dep.Key is a string representation of a guid... and DependencyKey is a property of type Guid

    <ctl:DependencyEditor DependencyKey="<%= new Guid(dep.Key) %>" runat="server" />
CRice