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

Dynamica PageView Creation with Single User Control

3 Answers 153 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Purushothama
Top achievements
Rank 1
Purushothama asked on 22 Aug 2016, 02:16 PM

Hi,

I am using RadTabStrip. I am dynamically adding PageView on Tab Click.  Now, in every pageVirew i am trying to load a single usercontrol containing a Rad Grid with different Data Source based on the tab Name.

I am able to load the user control, but the problem is after clicking all (3) tabs when i open the previous tabs, i have RadGrid with latest data.Since i am using the same usercontrol(with rad grid), same data is loaded in all the tabs. 

As per my requirement, I want the previous tabs with the corresponding loaded data. Could you please provide your feedback on this ?

3 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Tsvetanov
Telerik team
answered on 25 Aug 2016, 11:13 AM
Hello Purushothama,

Could you, please give us a bit more details on your implementation. How do you configure what data source your Grid should use? Post also any other information that could be relevant to this case.

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Purushothama
Top achievements
Rank 1
answered on 26 Aug 2016, 04:44 PM

Hello Veselin ,

Please find below the code behind of WebForm1.aspx.cs :

------------------------------------------------------------

protected void Page_Init(object sender, System.EventArgs e)
{

AddRequestTab("Request1");
AddRequestPageView(RadTabStripRequest.FindTabByText("Request1"));

 

AddRequestTab("Request2");

AddRequestTab("Request3");

AddRequestTab("Request4");

}

 

private void AddRequestTab(string tabName)
{
RadTab tab = new RadTab();
tab.Text = tabName;
tab.ImageUrl = imageUrl;
RadTabStripRequest.Tabs.Add(tab);

}

protected void RadMultiPageRequest_PageViewCreated(object sender, RadMultiPageEventArgs e)
{

string userControlName = "RequestUserControl.ascx";
Control userControl = Page.LoadControl(userControlName);
userControl.ID = e.PageView.ID + "_userControl";
e.PageView.Controls.Add(userControl);

}

 

private void AddPageView(RadTab tab)
{
RadPageView pageView = new RadPageView();
pageView.ID = tab.Text;
RadMultiPageRequest.PageViews.Add(pageView);
tab.PageViewID = pageView.ID;
}

----------------------------------------------------

Please find below the content from RequestUserControl.ascx file:

----------------------------------------------------

protected void Page_Load(object sender, EventArgs e)
{

RadTabStrip rad = this.Parent.FindControl("RadTabStripRequest") as RadTabStrip;

//Need to bind data based on selected tab text name
BindGrid( rad.SelectedTab.Text);

}

public void BindGrid(string DataSource)

{

DataTable dt= //Get data from based on the selected Tab Name (dataSource)

radGridRequest.DataSource = dt;
radGridRequest.DataBind();

}

----------------------------------------------------

JS to disable the postback of already created Tabs

function OnTabSelecting(sender,args){ if(args.get_tab().get_pageViewId())args.get_tab().set_postback(false)}

 

On each tab click, all the usercontrol instances which are dynamically added are binding with the same data source. For example By default Request1 tab will be loaded (data is fine here). If I click on the next tab i.e. Request2, even user control which is there in Request1 also will be binded with the Request2 DataSource.

 

0
Veselin Tsvetanov
Telerik team
answered on 29 Aug 2016, 08:20 AM
Hello Purushothama,

Thank you for the additional information provided.

The problem in this implementation is the fact that each time a postback occurs the Page_Load method for all of the RequestUserControls gets called. Therefore, on each postback the DataSource for the Grid in the RequestUserControls is changed, according to the last selected Tab.

I would suggest you to perform a check in this Page_Load method, confirming that the Grid on the RequestUserControl being loaded does not have a DataSource set. If it already has, you simply do not bind the Grid again.

Attached you will find a simple implementation of the above, replacing the Grid with a simple RadLabel control. It implements the above logic which would be applicable for your scenario.

Regards,
Veselin Tsvetanov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
TabStrip
Asked by
Purushothama
Top achievements
Rank 1
Answers by
Veselin Tsvetanov
Telerik team
Purushothama
Top achievements
Rank 1
Share this question
or