View Full Version : Binding.First steps.HELP!
I write the following code:
public class User
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
}
public class WebForm1 : Spring.Web.UI.Page
{
[Binding ("Text","UserInfo.Name")]
protected System.Web.UI.WebControls.TextBox TextBox1;
private User user;
public User UserInfo
{
get { return user; }
set { user = value; }
}
private void Page_Load(object sender, System.EventArgs e)
{
UserInfo = new User();
UserInfo.Name = "User name";
}
...
}
and I have the error:
Specified cast is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Specified cast is not valid.
Source Error:
Line 45: //
Line 46: InitializeComponent();
Line 47: base.OnInit(e);
Line 48: }
Line 49:
Please help me. What am I doing wrong?
Rick Evans
07-14-2005, 07:37 AM
Hiya
I'd love to help, but in order to do so could you provide the full unexpurgated stack trace of the error?
The fact that you're getting an InvalidCastException is indicative of something other than Spring.NET data binding being the issue (I may be wrong), 'cos from what you've posted, the databinding looks pretty plain vanilla.
Please do post your full stack trace. I daresay you could email me your page source should you have any issues regarding confidentiality.
Ciao
Rick
Rick Evans
07-14-2005, 02:25 PM
Hi Dmitrij
I see the issue now... in order to use the bidirectional databinding features of Spring.NET, you have to buy into (i.e. use) the other features of Spring.NET's ASP.NET support.
You MUST use the Spring.NET provided PageHandlerFactory for your databound pages. You MUST also provide an application context for your data bound pages.
In practice, this means that you must have this XML fragment in your Web.config file...
<httpHandlers>
<add verb="*" path="*.aspx" type="Spring.Web.Support.PageHandlerFactory, Spring.Web" />
</httpHandlers>
You must also have a section within your Web.config file that declares an application context...
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
</objects>
</spring>
If you uncomment the relevant sections from your Web.config file (the one that you emailed to me), everything will work as expected. To wit (and don't forget to uncomment / add the <httpHandler/> snippet from above too)...
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
</configSections>
<spring>
<context type="Spring.Context.Support.WebApplicationContext, Spring.Web">
<resource uri="config://spring/objects" />
</context>
<objects xmlns="http://www.springframework.net">
<object type="WebForm1.aspx"/>
</objects>
</spring>
The fact that you should have to buy into the other features of Spring.NET in order to get bidirectional databinding is not altogether a bad thing. The benefits of dependency injection are legion... I should add that the ASP.NET web support in Spring.NET is not 100% finalized yet, and that the documentation could be substantially improved. Some example applications are in development and will be available soon (ish).
Ciao
Rick
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.