Wednesday, March 21, 2012

TabContainer in Master Page, TabPanel in Content Page...does it work?

I just started a new project, and before I go wasting my time and energy on this concept, let me find out for certain. If in my Master Page, I declare a TabContainer, and between those opening and closing tags I put the declaration of the ContentPlaceholder, then in each Content page, the entireity of the content is inside a TabPanel...will that work? Can I do it that way at all, even if there have to be some workarounds? And if there are, what are those workarounds?

Appreciate any help anybody can offer!

Hi Ando,

Yes , you can do it like this .

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server">
<HeaderTemplate>
Tab1</HeaderTemplate>
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server">
<HeaderTemplate>
Tab2</HeaderTemplate>
<ContentTemplate>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
</form>

ContentTemplate works like a container(Div);

I hope this help.

Best regards,

Jonathan


Does this example only work on a certain AJAX.NET release (I'm current using release 10920)? It'll certainly be handy if this method worked :)

I've tried the above but I'm getting the following Exception:

System.Web.HttpException was unhandled by user code
Message="TabContainer cannot have children of type 'System.Web.UI.WebControls.ContentPlaceHolder'."
Source="AjaxControlToolkit"
ErrorCode=-2147467259
StackTrace:
at AjaxControlToolkit.TabContainer.AddParsedSubObject(Object obj) in d:\E\AjaxTk-AjaxControlToolkit\Release\AjaxControlToolkit\Tabs\TabContainer.cs:line 311
at System.Web.UI.Control.System.Web.UI.IParserAccessor.AddParsedSubObject(Object obj)
at ASP.presentation_masterpage_master.__BuildControlTabContainer1() in d:\Data\Visual Studio 2005\WebSites\PTOK\Presentation\MasterPage.master:line 16
at ASP.presentation_masterpage_master.__BuildControlform1() in d:\Data\Visual Studio 2005\WebSites\PTOK\Presentation\MasterPage.master:line 11
at ASP.presentation_masterpage_master.__BuildControlTree(presentation_masterpage_master __ctrl) in d:\Data\Visual Studio 2005\WebSites\PTOK\Presentation\MasterPage.master:line 1
at ASP.presentation_masterpage_master.FrameworkInitialize() in d:\Data\Visual Studio 2005\WebSites\PTOK\Presentation\MasterPage.master.cs:line 912306
at System.Web.UI.UserControl.InitializeAsUserControlInternal()
at System.Web.UI.UserControl.InitializeAsUserControl(Page page)
at System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection)
at System.Web.UI.Page.get_Master()
at System.Web.UI.Page.ApplyMasterPage()
at System.Web.UI.Page.PerformPreInit()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


Hi SpaceToaster,

I have tested on V10920 and it works pretty well. Please make sure that you have put the sample code inside the Master.page and make the content page as simple as possible. For example,

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>

<script runat="server">

</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<%=DateTime.Now.ToString()%>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
2131
</asp:Content>

I hope this help.

Best regards,

Jonathan


Hi Jonathan,

I don't see how the code you posted above is the same as the original example you have shown.

The exception was thrown after I've placed a ContentPlaceHolder inside a TabContainer.

Thanks,


Hi Spacetoaster,

My first reply provide Master Page code and the second reply provide the Content Page code. So combine them will get a test sample.

Would you please test it on your machine? I have tested it on IE7 and Firefox2. Please make sure the TabContainer which contains aContentPlaceHolder is located inside the Master Page. If this doesn't work, please feel free to let me know with a simple repro which certainly can reproduce your issue.

Hope this help.

Best regards,

Jonathan


Hello Jonathan ;

I m using the same style as you replied in post 2 of this thread. I can add my one .aspx page in first Contentplaceholder1 but cant add second .aspx page in the second Contentplaceholder2 which is in second tab?

FYI: I have two pageload events in these two different pages? Do i have remove one ??


Hi Saqib_dotnet,

saqib_dotnet:

FYI: I have two pageload events in these two different pages? Do i have remove one ??

Yes, or one pageLoad function will be ignored.

Best regards,

Jonathan


So i have two different aspx file.

Tab1.aspx and Tab2.aspx files.

I will keep Page_Load Tab1.aspx and remove from the other, then how the other page will be processed with the first page? I mean what will invoke the Tab2.aspx functions?

REgards


Hi Saqib_dotnet,

UserControls located in the same page works as these functions & controls are put in the same page. So you can call the function directly.

saqib_dotnet:

I will keep Page_Load Tab1.aspx and remove from the other, then how the other page will be processed with the first page? I mean what will invoke the Tab2.aspx functions?

Please make sure that the right function name is pageLoad but not PageLoad or Page_Load. I suggest that you can change the pageLoad function to a common js fucntion (modify name) and remain them in the original place. Then , add pageLoad function to the end of the page, now we can call the other functions on pageLoad.

Best regards,

Jonathan



Hi Saqib_dotnet,

If you mean server side method, all Page_Loads will be executed. If it is a client side function(javascript function), you should usepageLoad function.

Best regards,

Jonathan


I thought we are talking about the Page_Load event handler function ?

Is there any other function pageLoad?


Hi Saqib_dotnet,

That's based on your implementation. I think you should add breakkpoints and find out the exact root cause.

Best regards,

Jonathan


First of all i never went so far where I worked with JS functions. All i m using is ScriptManager and it looks like, it is handling everything.

Now my question is: I created master page with two tabs like described above. Then added two different aspx pages to the ContentPlaceHolders respectively. Both pages are in two different files and both have server side Page_Load functions.

Now when i run theApplication, only my defult page get populated in first Tab but not the other page which should be populated in second Tab.

Where the problem is?

Also, I m trying to load the second tab when user clicks it? What should I do for this as well.

Regards

No comments:

Post a Comment