Saturday, March 31, 2012

Set a custom object property in a user control

hi, i have a user control that have a property MyProp of type MyObject.

MyObject also have a property named Prop1;

I want to set Prop1 in the aspx.

For example

<User:MyControl id="control>

<MyProp Prop1="value" />

</User:MyControl>

and

public class MyObject

{

public string Prop1 {get; set;}

}

This code works but i can't go to Design View becouse contents isn't allowed between openin and closing tag of an user control)

Somebody have a solution? ( i don't ant to change my user Control to a server control)

thanks

You cant have content between opening and closing tags.

Your code should be like as below:

<User:MyControl id="control"

Prop1="value">

</User:MyControl>

Try this and let me know if any issues


thanks for your reply but i don't need to set a property of my control, i need to set some properties of an object returned by a property of my control and

i neither want to remap all this properties to some new properties of the control becouse are too match;

a better example is (some implementation details are hidden):

class User

{

public string Name { set; }

public string Surname {set;}

}

class UserView : UserControl

{

public User TargetUser {get;}

}

and in the page

<MyControls:UserView id="userView1">

<TargetUser Name="sam" Surname="foofoo" />

</MyControls:UserView>

This code works but i can't switch to DesignView becouse Visual Studio see contents into my control tags.

I want know if there's a way to set Name and Value property of internal User object into the aspx without problems with visual studio parser.


0 comments:

Post a Comment