Wednesday, March 21, 2012

TabContainer question.

Hi,
After reading some messages on this forum, I finally found an issue to my problem about the headerText that displays when I set to false the visible tabpanel.
I use this syntax
TabContainter[1].Enabled=false;

Now I really need help on this topic.
As I said, I have a tabcontainer with 3 tabpanels.
When I am in "created" mode (that means the user will create a new item), it's only the first tabpanel is displayed.
So I what I want is when the user presses the "Add" button of the first TabPanel, the 2 other panels become visible.

I thank you in advance for your precious help.
Stan

Here's a part of my current code that doesn't work (of course)..

<cc1:TabContainer ID="myTabContainer" runat="server" Width="905" >
<cc1:TabPanel ID="myFistTab" runat="server" HeaderText="Identité">
<ContentTemplate>
<asp:UpdatePanel ID="upd" runat="server">
<ContentTemplate>
<asp:TextBox ID="txtname" runat="server" /><br />
<asp:Button ID="btnupd" OnClick="btnupd_Click" runat="server" Text="Add" />
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="mySecondTab" runat="server" HeaderText="Details">
<ContentTemplate>bla bla</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="myThirdTab" runat="server" HeaderText="Stats" >
<ContentTemplate>Bla bla</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>

The code behind

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
myTabContainer.Tabs[1].Enabled = false;
myTabContainer.Tabs[2].Enabled = false;
}
}

protected void btnupd_Click(object sender, EventArgs e)
{
updateDataBase();
myTabContainer.Tabs[1].Enabled = true;
myTabContainer.Tabs[2].Enabled = true;
}


I think you need to set AutoPostBack on the TabContainer to "true":

<cc1:TabContainer ID="myTabContainer" runat="server" AutoPostBack="true" Width="905" >

If that doesn't solve your problem, try removing the current UpdatePanel you have inside the tabPanel and wrapping the entire TabContainer in an UpdatePanel and see if the tabs show when btnupd_Click event fires.


Kylen,

I test with AutoPostBack sets to true. It doesn't work.
If I remove the UpdatePanel that is inside the TabPanel, everything works, but all the page is reloaded.
I suppose I have to call a jscript function to "enabled" the tabs but I don't know how to do it.
Stan


Hi Stan,

The right suggestion has been given by Kylen. Here is the sample. Hope it helps.

ASPX Code:

<%@. Page Language="C#" AutoEventWireup="true" CodeFile="TabTest.aspx.cs" Inherits="TabTest" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="upd" runat="server"> <ContentTemplate> <cc1:TabContainer ID="myTabContainer" runat="server" Width="905"> <cc1:TabPanel ID="myFistTab" runat="server" HeaderText="Identité"> <ContentTemplate> <asp:TextBox ID="txtname" runat="server" /><br /> <asp:Button ID="btnupd" OnClick="btnupd_Click" runat="server" Text="Add" /> </ContentTemplate> </cc1:TabPanel> <cc1:TabPanel ID="mySecondTab" runat="server" HeaderText="Details"> <ContentTemplate> bla bla</ContentTemplate> </cc1:TabPanel> <cc1:TabPanel ID="myThirdTab" runat="server" HeaderText="Stats"> <ContentTemplate> Bla bla</ContentTemplate> </cc1:TabPanel> </cc1:TabContainer> </ContentTemplate> </asp:UpdatePanel> </form></body></html>

If any problems, please let me know!

No comments:

Post a Comment