This is a migrated thread and some comments may be shown as answers.

Is it possible to support data-binding when loading user control into pageview of my tabstrip?

4 Answers 279 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
AdrianTaylor
Top achievements
Rank 1
AdrianTaylor asked on 14 Apr 2010, 04:46 PM
How can I support data-binding in a user control (ascx) when I am using Page.LoadControl to load a page into a MultiPage PageView which I am creating at runtime? 

The Tabstrip / Load on Demand RadPageView demo does use a datasource but Eval() or Bind() methods are not being used.

I don't want to move my FormView into the user control as there a additional user controls, one for each tab infact.  Must I do all my data binding in code-behind and not do anything declaratively in the user controls?  If so, is this best placed in the PageView OnLoad event or in an event of my user control?

What I am trying to achieve would make for a great demonstration: A fully-featured tabstrip of pages across a single, two-way databound form in which the code for each tab is stored in seperate files (user controls) instead of a single, large file.

Can you suggest other ways to achieve this?

I also understand that this question is more about data binding in user controls than it is about RadTabStrip however I suspect that anyone using RadMultiPage is likely to have addressed this problem before.

Thanks.

4 Answers, 1 is accepted

Sort by
0
Pierre
Top achievements
Rank 1
answered on 15 Apr 2010, 07:33 PM
Hi Adrian,

I haved similar problem using Wizard tabstrip sample and one UC using a standard Grid and Databind / Rebind().  After some testing the problem is that i have linked the Bind event at Page_Load no postback. Could you tried creating your link event only at page Load event of your usercontrol. Is working for me. If not could paste your initial bind event
 
Regards, Romi.
0
AdrianTaylor
Top achievements
Rank 1
answered on 20 Apr 2010, 12:13 PM
Thanks for you reply Romi.

In my case I was trying to add the tab and load the associated user control during Page_Load as per the demo.  The databinding of controls in the user control was failing (before I could do any postback) with the error, "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."

There is lots of help out there for this problem but mostly geared towards one-way databinding. 

In my case I need two-way databinding.

I haven't fully addressed the original problem I raised but if anyone is interested, this is where I find myself today:


I have stopped trying to load the tabs and user controls dynamically so I can focus on the databinding problem.

Given a page with two user controls within a databound formview like that below:

<%@ Register TagPrefix="pv" TagName="PageViewAAA" Src="PageViewAAA.ascx" %> 
<%@ Register TagPrefix="pv" TagName="PageViewBBB" Src="PageViewBBB.ascx" %> 
...  
<FormView DataSourceID="FormDataSource" ...> 
  <EditItemTemplate> 
    <telerik:RadMultiPage runat="server" ID="MultiPage1" SelectedIndex="0">  
      <telerik:RadPageView runat="server" Width="100%" ID="PageViewAAA" > 
        <pv:PageViewAAA runat="server" ID="PageViewAAAControl"  /> 
      </telerik:RadPageView> 
      <telerik:RadPageView runat="server" Width="100%" ID="PageViewBBB" > 
        <pv:PageViewBBB runat="server" ID="PageViewBBBControl"  /> 
      </telerik:RadPageView> 
    </telerik:RadMultiPage> 
  </EditItemTemplate> 
</FormView> 
 

My user controls now inherit BindableUserControl instead of UserControl to allow for two-way databinding.

BindableUserControl inherits UserControl and is offered as a solution by David Fowl on his blog post, Data Binding 3.0.

Instead of binding the Text property of a TextBox using Text="<%# Bind("FirstName") %>", David binds using the WPF-ish Binding="{Text=FirstName, Mode=TwoWay}".

<%@ Control Language="C#" AutoEventWireup="true" ClassName="PageViewAAA">  
...  
<telerik:RadTextBox ID="FirstName" runat="server" Binding="{Text=FirstName, Mode=TwoWay}" /> 


0
Pierre
Top achievements
Rank 1
answered on 20 Apr 2010, 08:18 PM
Hi Adrian,

Could you triing using one simple pageview and addind directly your control inside not as UC to get if is working in this case. I canĀ“t get why your control is not working if your DataSourceID is correctly linked. Paste your error if not. You can try other solution linking the FormView directly in your usercontrols in place of your main page.

regards


0
AdrianTaylor
Top achievements
Rank 1
answered on 21 Apr 2010, 10:06 AM
If I copy the contents of the user control into my PageView, two-way databinding works.

If I use the user control I cannot get two-way databinding working without using David Fowl's BindableUserControl class.

However this works well.  I am only lacking the dynamic loading feature I also need.  Specifically, using Page.LoadControl in the PageViewCreated event to load each control only when required.  I suspect this is not working because my form is binding before the control is loaded.

For this reason I have started a new topic Data binding dynamically loaded user controls in a dynamically loaded RadPageView (FormView complications).

I understand that it is more productive for me to ask specific and direct questions and I apologise for not staying on one subject.  Slowly I am trying to pinpoint the smaller questions in what began as the very broad subject I have been struggling with.
Tags
TabStrip
Asked by
AdrianTaylor
Top achievements
Rank 1
Answers by
Pierre
Top achievements
Rank 1
AdrianTaylor
Top achievements
Rank 1
Share this question
or