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

Multpage Created Issue

5 Answers 172 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Randima
Top achievements
Rank 1
Randima asked on 22 Aug 2012, 05:41 AM
Hi,

I am having a dynamic tab control and multipage control. When I add new tab and pageview when in a button click,
radMultiPage_PageViewCreated(object sender, RadMultiPageEventArgs e) event fire and initialize the conntrol

Requirement : when I select a item from dropdown and click add button. New tab and page view should be added. Load usercontrol
Inside the page view 

HTML --
<asp:dropdownlist id="ddlLanguages" runat="server">
</asp:dropdownlist>
<asp:linkbutton id="lbtAddLanguage" runat="server" text="Add" tooltip="Click to add this language"></asp:linkbutton>

<asp:panel id="pnlOuter" runat="server">
    <div id="divTab" runat="server">
     <asp:label id="lblTime" runat="server"></asp:label>
        <rad:radtabstrip id="TabStrip" runat="server" multipageid="MultiPage"
            autopostback="False">
            <tabs>
            </tabs>
        </rad:radtabstrip>
        <rad:radmultipage id="MultiPage" runat="server">
        </rad:radmultipage>
    </div>
</asp:panel>


Code --

protected override void OnInit(EventArgs e)
		{
			
			lbtAddLanguage.Click += new EventHandler(lbtAddLanguage_Click);
			MultiPage.PageViewCreated += new RadMultiPageEventHandler(radMultiPage_PageViewCreated);
			
			
		}

void lbtAddLanguage_Click(object sender, EventArgs e)
		{
			RadTab		tab = new RadTab();
			
			ListItem item = ddlLanguages.SelectedItem;
			tab.Text		= item.Text;
			RadPageView	view = new RadPageView();
			view.ID			= item.Value;
			tab.PageViewID = view.ID;
			tab.Selected = true;
			
			TabStrip.Tabs.Add(tab);
			MultiPage.PageViews.Add(view);
 
		}

void radMultiPage_PageViewCreated(object sender, RadMultiPageEventArgs e)
		{
			
			Details		detailControl		= LoadControl(Constant.CONTROL_WIZARD_DETAILS) as Details;
			if (detailControl != null)
			{
				detailControl.SelectedLanguage	= GetLanguage();
				detailControl.LoadControls();
				e.PageView.Controls.Add(detailControl);
			}
			
		}


My issue is, When I click the button to add tabs, PageViewCreated event fires before the button click and try to Initialize all the page views. How can we stop this. Thanks

5 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 24 Aug 2012, 12:00 PM
Hi Randima,

You could not prevent the PageViewCreated event to fire, since you create dynamically the PageViews. You could simply use the lbtAddLanguage_Click event handler to load your UserControl for each newly created RadPageView and RadTab.

Greetings,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rabeek Ahamed
Top achievements
Rank 1
answered on 03 Sep 2012, 12:11 PM
I am also facing the same issue.

1. I added a tab1 dynamiclly with pageview1.
2. I did some entries in the pageview1 controls.
3. Now, I am adding i an tab2 dynamically with pageview2.

The existing pageview1 is recreated and reloaded and my control's values lost in the pageview1. When I debug the code, the pageviewCreated event is fired for the pageview1 and recreated the pageview1 when I dynamically create pageview2 (tab2).

How can I stop firing the pageviewcreated event for pageView1 when tab2 is created.

Please help.

private void AddTab(string tabName, string tabValue)
        {
            //Existing tab content url is empty when postback happens
            //So, Add content url property for the existing tabs
            foreach (RadTab cTab in RadTabStrip1.GetAllTabs())
            {
                if (cTab.Index != 0)
                {
                    RadPageView pv = cTab.PageView;
                    pv.ContentUrl = cTab.Value + ".aspx";
                }
            }
  
            //Open existing tab
            var rt = RadTabStrip1.GetAllTabs().Where(x => x.Value == tabValue);
              
            if (rt.Count() > 0)
            {
                RadTab rtSel = rt.First() as RadTab;
                rtSel.Selected = true;
                RadMultiPage1.SelectedIndex = rtSel.Index;
                RadTabStrip1.DataBind();
                return;
            }
  
            //Create new tab
            RadTab tab = new RadTab();
            tab.Text = tabName;
            tab.Value = tabValue;
            tab.PostBack = false;
            RadPageView pageView = new RadPageView();
  
            pageView.ID = tabValue;
            pageView.ContentUrl = tabValue + ".aspx";
            pageView.ViewStateMode = System.Web.UI.ViewStateMode.Enabled;
            pageView.CssClass = "pageView";
            RadMultiPage1.PageViews.Add(pageView);
  
            tab.PageViewID = tabValue;
            RadTabStrip1.Tabs.Add(tab);
  
            RadTabStrip1.DataBind();
  
            tab.Selected = true;
            RadMultiPage1.SelectedIndex = tab.Index;
        }

protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)
        {
            //string userControlName = e.PageView.ID + "CS.ascx";
            //Control userControl = Page.LoadControl(userControlName);
            //userControl.ID = e.PageView.ID + "_userControl";
            //e.PageView.Controls.Add(userControl);
  
            e.PageView.ContentUrl = e.PageView.ID + ".aspx";
        }

0
Nencho
Telerik team
answered on 05 Sep 2012, 10:39 AM
Hi Rabeek,

Could you elaborate a bit more about your scenario?
How do you use the AddTab method - on an event handler of a specific button or on the Page_Load event?
In addition, did you review our online demo here, where a similar to your approach is implemented?


Kind regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Rabeek Ahamed
Top achievements
Rank 1
answered on 05 Sep 2012, 12:14 PM
As you said, I refered the demo and implemented my code. But, I am loading the page view content with ContentUrl property instead of user control.

My Design:
<telerik:RadTabStrip ID="RadTabStrip1" runat="server" Skin="Default" Style="z-index: 3000;"
                        SelectedIndex="0" MultiPageID="RadMultiPage1" OnDataBinding="RadTabStrip1_DataBound"
                        EnableEmbeddedSkins="false" CssClass="RadTabStrip RadTabStrip_Galaxy" ClickSelectedTab="false"
                        UnSelectChildren="false">
                        <TabTemplate>
                            <span class="textWrapper">
                                <%# DataBinder.Eval(Container, "Text") %></span> <span class="ie6shim"></span>
                            <span class="closeicon">
                                <asp:ImageButton alt="close" runat="server" ID="imgClose" ImageUrl="~/Images/icon_close_rect.png" /></span>
                        </TabTemplate>
                        <Tabs>
                            <telerik:RadTab runat="server" Text="Overview" Value="Overview" PageViewID="RadPageMain">
                            </telerik:RadTab>
                        </Tabs>
                    </telerik:RadTabStrip>
                      
                    <telerik:RadMultiPage Style="width: 98%" ID="RadMultiPage1" runat="server" SelectedIndex="0"
                        OnPageViewCreated="RadMultiPage1_PageViewCreated" CssClass="multiPage" RenderSelectedPageOnly="false">
                        <telerik:RadPageView ID="RadPageMain" runat="server" SelectedIndex="0" CssClass="pageView">
                              
                                    <table>
                                        <tr>
                                                          <td>

<asp:Button ID="btnTab1" Text="Tab1" CommandName="Tab1" runat="server"

                                OnClick="btnAddTab_Click" />

 

 

 

 

 

   </td>

                                        </tr>

<tr>

<td >

<asp:Button ID="btnTab2" Text="Tab2" CommandName="Tab2" runat="server" OnClick="btnAddTab_Click" />

</td>

</tr>


                                    </table>
</telerik:RadPageView>
                    </telerik:RadMultiPage>

The tab and pageview will be created dynamically when btnAddTab_Click event is fired.

1. Click on Tab1 button --> new tab "Tab1" is created & "Tab1.aspx" as pageview content.
2. Do some data entry in "Tab1".
3. Now click on Tab2 button -->  New tab "Tab2" will be created & "Tab2.aspx" as pageview content.
4 Now when select the Tab1, the pageview content in the tab1 is recreated back to old state. ie, the page lost the data entered.

I hope I explained my scenario. Kindly help me to resolve this issue.
0
Nencho
Telerik team
answered on 10 Sep 2012, 11:16 AM
Hello Rabeek,

Since you use the ContentUrl property to assign a certain PageView, you could not persist the state of any control inside the that PageView. Each time a Tab is rendered, new  GET request is performed because of the ContentUrl property, thus you could not persist the state of the previously filled data.


Regards,
Nencho
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TabStrip
Asked by
Randima
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Rabeek Ahamed
Top achievements
Rank 1
Share this question
or