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

Page Multiview passing parameter to control

1 Answer 125 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 10 Mar 2011, 05:40 PM

I am testing the trial version of Telerik controls and need to assess how it will handle a very specific situation. I am using a close derivative of the load on demand sample. The key differences are that each pageview uses the same control and I also have a public property that I set to control the pageview. The problem I am facing is that nothing displays onload or when I change tabs. Below is the code that is used on the tab page. Below I will mark the lines that are different from the Load on Demand Sample. Does anybody have an idea as to what I am doing wrong?

 

 

 

 

 

 

 

 

 

 

<telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1"  
</telerik:RadAjaxLoadingPanel
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadTabStrip1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadTabStrip1" />
                <telerik:AjaxUpdatedControl ControlID="RadMultiPage1" 
                                LoadingPanelID="LoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="RadMultiPage1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadMultiPage1"
                            
 LoadingPanelID="LoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<script type="text/javascript">
    function onTabSelecting(sender, args) {
        if (args.get_tab().get_pageViewID()) {
            args.get_tab().set_postBack(false);
        }
       }
</script>
  
<div style="float:left;">
    <telerik:RadTabStrip OnClientTabSelecting="onTabSelecting" ID="RadTabStrip1" 
        SelectedIndex="0" CssClass="tabStrip"
        runat="server" MultiPageID="RadMultiPage1" Skin="Sitefinity"   
        OnTabClick="RadTabStrip1_TabClick" Orientation="VerticalLeft"  
    </telerik:RadTabStrip
</div>  
<div style="float:left;"
    <telerik:RadMultiPage ID="RadMultiPage1" runat="server" 
            SelectedIndex="0" OnPageViewCreated="RadMultiPage1_PageViewCreated"
    </telerik:RadMultiPage>
</div>

 

and here is the Code Behind.

 

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    
           //This is different I am using a datasource to generate the tabs
        RSOracleData RSOD = new RSOracleData();
        RSOD.ConnString = ConfigurationManager.ConnectionStrings["OracleConnection"].ToString();
        DataSet DS = RSOD.GetPageTabs(Thread.CurrentThread.CurrentUICulture.ToString(), "Laws");
        RadTabStrip1.DataSource = DS;
        RadTabStrip1.DataTextField = "TABNAME";
        RadTabStrip1.DataValueField = "TABID";
        RadTabStrip1.DataBind();
        if (DS.Tables.Count > 0)
        {
            AddPageView(RadTabStrip1.FindTabByText(DS.Tables[0].Rows[0]["TABNAME"].ToString()));
        }
    }
}

private void AddTab(string tabName)
{
    RadTab tab = new RadTab();
    tab.Text = tabName;
    RadTabStrip1.Tabs.Add(tab);
}
  
protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)
{ 
        //This is different I am loading one particular control and setting a property in it     
    webproject1.Controls.PageViewGrid PVControl = new webproject1.Controls.PageViewGrid();
    PVControl.PageViewID = Convert.ToInt32(e.PageView.ID.Replace("PV", ""));   
    PVControl.ID = e.PageView.ID + "_userControl"  
    e.PageView.Controls.Add(PVControl);   
  
  
private void AddPageView(RadTab tab)   
  
    RadPageView pageView = new RadPageView();
     //I am using a value to determine the tab instead of using the text
    pageView.ID = "PV" + tab.Value;
    RadMultiPage1.PageViews.Add(pageView);    
    tab.PageViewID = pageView.ID;
}

protected void RadTabStrip1_TabClick(object sender, RadTabStripEventArgs e)
{
    AddPageView(e.Tab);
    e.Tab.PageView.Selected = true;
}

 

1 Answer, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 16 Mar 2011, 02:30 PM
Hi Joseph,

In order to load a user control dynamically, you should use: Page.LoadControl() method. In your case the user control is instantiated, but not loaded into the page. When you load user control with the above mentioned method, in order to be able to access its public properties, you should cast it to the type of your custom control.

I'm sending you a sample page, where I've used a simple user control, which contains RadComboBox. Try to follow the example I've provided and if you still have queries do not hesitate to contact us again.

Regards,
Dimitar Terziev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
TabStrip
Asked by
Joseph
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Share this question
or