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

Problem with Wizard Example where page is from a Master page

9 Answers 158 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Ronnie
Top achievements
Rank 1
Ronnie asked on 28 May 2010, 09:29 AM
Hello,

I've created a wizard like pages, exactly like in the example provided.  I'm getting the "Object reference not set to an instance of an object." exception and can not understand why.  
After much troubleshooting, I got it working, but not as desired.  The difference is that the WebForm.aspx that contains the RadTabStrip1 and the RadMultiPage1 only works when NOT within a master page.

I've been searching all over on how to reference, find,  or whatever needs to be done but can't seem to find a fix.
Here's where I receive an error when select the 1st "NEXT" from the 1st pageview:
 
Line 208:      {  
Line 209:         RadTabStrip tabStrip = (RadTabStrip)Page.FindControl("RadTabStrip1");  
Line 210:         RadTab tab = tabStrip.FindTabByText("Tab B");   // <-------------------------- ERROR OCCURS HERE  
Line 211:         tab.Enabled = true;  
Line 212:         tab.Selected = true;  
   
 

Once again, it works when the ASPX page is an independenf form.  When it's part of a MASTER page it does not work.

Thank you in advance,
Ronnie

9 Answers, 1 is accepted

Sort by
0
Ronnie
Top achievements
Rank 1
answered on 28 May 2010, 09:37 AM

Here's is the actual C# method:

      private void GoToNextTab()  
      {  
         RadTabStrip tabStrip = (RadTabStrip)Page.FindControl("RadTabStrip1");  
         RadTab tab = tabStrip.FindTabByText("Tab B");      // <-------------- ERROR OCCURS HERE  
         tab.Enabled = true;  
         tab.Selected = true;  
 
         GoToNextPageView();  
      } 


Thanks again,
Ronnie
0
Veronica
Telerik team
answered on 28 May 2010, 01:57 PM
Hi Ronnie,

The problem is in the way you find the controls. You use Page.FindControl() function:

private void GoToNextTab()   
      {   
         RadTabStrip tabStrip = (RadTabStrip)Page.FindControl("RadTabStrip1");   

You will not get the control through the Page because actually it is in the Master page to which this page is referrencing. The correct is Page.Master.FindControl():

RadTabStrip tabStrip = (RadTabStrip)Page.Master.FindControl("RadTabStrip1");

I've created a sample project analogical to the Wizard Demo but with a Master page as your requirement.
You may find it in the attached .zip file.

Hope this helps.

Best wishes,
Veronica Milcheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ronnie
Top achievements
Rank 1
answered on 28 May 2010, 09:23 PM
Hello Veronica,

Thank  you for your immediate response.

I tested the sample project and it works great ! 
But it's not exactly the problem I'm having, I guess I was not very clear in my explanation.  The RadTabStrip and RadMultiPage is in an ASPX page, where the ASPX is part of a MASTER.

I've modified your sample version a bit to re-create my scenario.  The only difference is I moved the RadTabStrip and other code from MasterPage.master of your sample and placed it in the Default.aspx and arrived at the same exception.

Here are my changes:
Moved from MasterPage.master to Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/MasterPage.master" %> 
<%@ Register Src="PreviewCS.ascx" TagName="PreviewCS" TagPrefix="uc1" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">  
 
   <telerik:RadScriptManager ID="ScriptManager" runat="server" /> 
    <div class="exampleWrapper">  
        <telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1" IsSticky="true">  
        </telerik:RadAjaxLoadingPanel> 
        <telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="LoadingPanel1">  
            <div style="float: left; width: 500px">  
                <telerik:RadTabStrip ID="RadTabStrip1" SelectedIndex="0" runat="server" MultiPageID="RadMultiPage1" 
                    Skin="Sunset" CssClass="tabStrip">  
                </telerik:RadTabStrip> 
                <telerik:RadMultiPage ID="RadMultiPage1" runat="server" SelectedIndex="0" OnPageViewCreated="RadMultiPage1_PageViewCreated" 
                    CssClass="multiPage">  
                </telerik:RadMultiPage> 
            </div> 
            <div class="previewWrapper">  
                <uc1:PreviewCS ID="previewControl" runat="server" /> 
            </div> 
        </telerik:RadAjaxPanel> 
    </div> 
      
</asp:Content> 
public partial class _Default : System.Web.UI.Page   
{  
    protected void Page_Load(object sender, EventArgs e)  
    {  
       if (!Page.IsPostBack)  
       {  
          AddTab("Personal Info"true);  
 
          RadPageView pageView = new RadPageView();  
          pageView.ID = "Personal";  
          RadMultiPage1.PageViews.Add(pageView);  
 
          AddTab("Education Info"false);  
          AddTab("Professional Info"false);  
       }  
    }  
 
    private void AddTab(string tabName, bool enabled)  
    {  
       RadTab tab = new RadTab(tabName);  
       tab.Enabled = enabled;  
       RadTabStrip1.Tabs.Add(tab);  
    }  
 
    protected void RadMultiPage1_PageViewCreated(object sender, RadMultiPageEventArgs e)  
    {  
       Control pageViewContents = LoadControl(e.PageView.ID + "CS.ascx");  
       pageViewContents.ID = e.PageView.ID + "userControl";  
 
       e.PageView.Controls.Add(pageViewContents);  
    }  

I also commented out 'UpdatePreview()' in the PersonalCS.ascx.cs nextButton_Click event.  That threw an exception too, but I haven't created the preview control in my project yet so I wanted to test it without it.

Thank you again for your assistance,
Ronnie

0
Accepted
Veronica
Telerik team
answered on 31 May 2010, 11:42 AM
Hi Ronnie,

I'm sorry for the misunderstanding.

The cause for the errors now is that you can not directly get the controls with Page.FindControl() function because when page is referring to a Master.page you'll need to get the ContentPlaceHolder first:

ContentPlaceHolder placeHolder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");

After that use the placeHolder object to get different controls e.g RadTabStrip1:

private void GoToNextTab()
        {
            ContentPlaceHolder placeHolder = (ContentPlaceHolder)Page.Master.FindControl("ContentPlaceHolder1");
            RadTabStrip tabStrip = (RadTabStrip)placeHolder.FindControl("RadTabStrip1");
            RadTab educationInfoTab = tabStrip.FindTabByText("Education Info");
            educationInfoTab.Enabled = true;
            educationInfoTab.Selected = true;
  
            GoToNextPageView();
        }

instead of :

RadTabStrip tabStrip = (RadTabStrip)Page.FindControl("RadTabStrip1");

Find the full code in the attached .zip file.

Please let me know if this was helpful.

Greetings,
Veronica Milcheva
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ronnie
Top achievements
Rank 1
answered on 01 Jun 2010, 08:43 AM
Veronica,
The second sample project, referencing the ContentPlaceHolder was what I needed.

Thank you again,
Ronnie
0
WebGeek
Top achievements
Rank 1
answered on 09 Sep 2010, 01:10 PM
I am having the same problem, but my setup is:
  1. MasterPage
  2. Nested MasterPage
  3. Page
  4. UserControl

Any suggestions?

0
Veronica
Telerik team
answered on 14 Sep 2010, 03:14 PM
Hello James,

Let we have Master Page called MasterPage.master with ContentPlaceHolder called "MainContent".
Then we create another Master page called Child.master which is referrencing the MasterPage.master as a Master:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Child.master.cs" Inherits="MasterPage"
    MasterPageFile="~/MasterPage.master" %>

For nested master pages you need the find the main ContentPlaceHolder first (in my example called "MainContent") and then the child ContentPlaceHolder (called "ChildContent1"). Here's the code:

private void GoToNextTab()
        {
            ContentPlaceHolder mainPlaceHolder = (ContentPlaceHolder)Page.Master.Master.FindControl("MainContent");
            ContentPlaceHolder childPlaceHolder = (ContentPlaceHolder)mainPlaceHolder.FindControl("ChildContent1");
            RadTabStrip tabStrip = (RadTabStrip)childPlaceHolder.FindControl("RadTabStrip1");
            RadTab educationInfoTab = tabStrip.FindTabByText("Education Info");
            educationInfoTab.Enabled = true;
            educationInfoTab.Selected = true;
  
            GoToNextPageView();
        }

Find the full code in the attached .zip file.

Please let me know if this was helpful.

Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
WebGeek
Top achievements
Rank 1
answered on 14 Sep 2010, 03:17 PM
Thanks for replying.  After working with it I finally figured it out.  I had one more control (loginview) in between the Master & Nested Master pages which was causing the problem. 

private void GoToNextTab()
    {
        ContentPlaceHolder placeHolder1 = (ContentPlaceHolder)Page.Master.Master.FindControl("cntPHPageContent");
        LoginView loginview = (LoginView)placeHolder1.FindControl("loginviewSecure");
        ContentPlaceHolder placeHolder1a = (ContentPlaceHolder)loginview.FindControl("SiteContent");
        RadTabStrip tabStrip = (RadTabStrip)placeHolder1a.FindControl("radTabStrip");
        RadTab Test2Tab = tabStrip.FindTabByText("Test 2");
        Test2Tab.Enabled = true;
        Test2Tab.Selected = true;
        GoToNextPageView();
    }
  
    private void GoToNextPageView()
    {
        ContentPlaceHolder placeHolder2 = (ContentPlaceHolder)Page.Master.Master.FindControl("cntPHPageContent");
        LoginView loginview = (LoginView)placeHolder2.FindControl("loginviewSecure");
        ContentPlaceHolder placeHolder2a = (ContentPlaceHolder)loginview.FindControl("SiteContent");
        RadMultiPage multiPage = (RadMultiPage)placeHolder2a.FindControl("radMultiPage");
        RadPageView Test2PageView = multiPage.FindPageViewByID("radPageViewTest2");
        if (Test2PageView == null)
        {
            Test2PageView = new RadPageView();
            Test2PageView.ID = "radPageViewTest2";
            multiPage.PageViews.Add(Test2PageView);
        }
        Test2PageView.Selected = true;
    }
0
Veronica
Telerik team
answered on 16 Sep 2010, 08:07 AM
Hi medicalwebgeek,

I'm glad you found the solution.
 
Feel free to ask me if you have furhther questions.

Greetings,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TabStrip
Asked by
Ronnie
Top achievements
Rank 1
Answers by
Ronnie
Top achievements
Rank 1
Veronica
Telerik team
WebGeek
Top achievements
Rank 1
Share this question
or