Dynamica PageView Creation with Single User Control

4 posts, 1 answers
  1. Purushothama
    Purushothama avatar
    6 posts
    Member since:
    Jun 2016

    Posted 22 Aug Link to this post

    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 ?

  2. Answer
    Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    290 posts

    Posted 25 Aug Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Purushothama
    Purushothama avatar
    6 posts
    Member since:
    Jun 2016

    Posted 26 Aug Link to this post

    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.

     

  5. Veselin Tsvetanov
    Admin
    Veselin Tsvetanov avatar
    290 posts

    Posted 29 Aug Link to this post

    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.
Back to Top