tabContainer's OnActiveTabChanged fires twice

I'm using the tabContainer from the ASP.NET AJAX Control Toolkit. It al works fine till I used the OnActiveTabChanged function. When I click a tab everything is normal exept the code in my handler fires twice. Both senderID's are the viewTabContainer and the ActiveTabIndex is also the same. Does anyone have an idea what can cause this problem? Looks like I doubleclick on a tab while the page is loaded ounce...

Code:
The tabs:
<cc1:TabContainer ID="viewTabContainer" Height="425" Width="100%" runat="server"
    AutoPostBack="True" OnActiveTabChanged="viewTabContainer_ActiveTabChanged">
    <cc1:TabPanel ID="persoonsTabPanel" runat="server">
        'Etc.


The Handler:
Protected Sub viewTabContainer_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    'Some code
End Sub

 
0
Benexx
7/13/2007 8:07:17 PM
asp.net.ajax_control_toolkit 17816 articles. 1 followers. Follow

14 Replies
1315 Views

Similar Articles

[PageSpeed] 4

Hi,

It seems to be all right with what you posted.

It will be helpful for trouble shooting if you post full source of the page. 

0
Raymond
7/18/2007 5:02:59 AM

The aspx code:

<cc1:TabContainer ID="viewTabContainer" Height="425" Width="100%" runat="server"
    AutoPostBack="True" OnActiveTabChanged="viewTabContainer_ActiveTabChanged">
    <cc1:TabPanel ID="persoonsTabPanel" runat="server">
        <HeaderTemplate>
            <asp:Label ID="persoonsTabLabel" runat="server"></asp:Label></HeaderTemplate>
        <ContentTemplate>
					' Large table
        </ContentTemplate>
    </cc1:TabPanel>
    <cc1:TabPanel ID="relatiesTabPanel" runat="server">
        <HeaderTemplate>
            <asp:Label ID="relatiesTabLabel" runat="server"></asp:Label></HeaderTemplate>
        <ContentTemplate>
            <table class="viewTable">
                <tr>
                    <td class="viewTableTD">
                        <asp:PlaceHolder ID="relatieViewPlaceHolder" runat="server" EnableViewState="false">
                        </asp:PlaceHolder>
                    </td>
                    <td class="viewTableTD">
                        <asp:PlaceHolder ID="relatieSelectPlaceHolder" runat="server" EnableViewState="false">
                        </asp:PlaceHolder>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </cc1:TabPanel>
    <cc1:TabPanel ID="financieelTabPanel" runat="server">
        <HeaderTemplate>
            <asp:Label ID="financieelTabLabel" runat="server"></asp:Label></HeaderTemplate>
        <ContentTemplate>
					' Large table
        </ContentTemplate>
    </cc1:TabPanel>
    <cc1:TabPanel ID="optieTabPanel" runat="server">
        <HeaderTemplate>
            <asp:Label ID="optieTabLabel" runat="server"></asp:Label></HeaderTemplate>
        <ContentTemplate>
            Optie
        </ContentTemplate>
    </cc1:TabPanel>
    <cc1:TabPanel ID="aTabPanel" runat="server">
        <HeaderTemplate>
            <asp:Label ID="aTabLabel" runat="server"></asp:Label></HeaderTemplate>
        <ContentTemplate>
            Testing tab
        </ContentTemplate>
    </cc1:TabPanel>
</cc1:TabContainer>

 

The aspx.vb code:

Partial Class Beheer_Deelnemer_Deelnemer
    Inherits System.Web.UI.Page

    Private d As Deelnemer
    Private _wijzigingen As Boolean

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        d = New Deelnemer

        If Not Page.IsPostBack Then
            getTaal()

            getView()
            checkView("all")
        End If
    End Sub

    Private Sub showAlert(ByVal type As String, Optional ByVal tekst As String = "")
        Select Case type
            Case "error"
                viewValidationSummary.Visible = True
                alertLabel.Visible = False
                alertPanel.Visible = True
            Case "alert"
                viewValidationSummary.Visible = False
                alertLabel.Text = tekst
                alertLabel.Visible = True
                alertPanel.Visible = True
            Case Else
                alertPanel.Visible = False
        End Select
    End Sub

    Protected Sub viewTabContainer_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        'The trouble code. Only by changing the tabs the code is execute twice.
        checkView("tabs") 'Rebuild tab contents
    End Sub

    Private Sub getView()
				'A lot of code to get the data
    End Sub

    Private Sub checkView(ByVal type As String)
        If type = "all" Or type = "tabs" Then
            Select Case viewTabContainer.ActiveTabIndex
                Case 0 
                Case 1 
                   Dim dr As New Deelnemer_relatie
                   dr.getRelaties(d.id, relatieViewPlaceHolder)
Case 2 Case 3 End Select End If If type = "all" Or type = "buttons" Then If d.nieuw Then toevoegenButton.Enabled = False Else toevoegenButton.Enabled = True End If End If Page.Validate() End Sub Private Sub setDeelnemer() 'A lot of code to save the data d.opslaan() End Sub Private Sub getTaal() Dim t As New Taal 'Get the language End Sub End Class

Code description:

The page is a simple page that allow changes to a table with students. On the second tab there is a view with different relations. The relations view is a bit heavy for the DB so I only want to load the data when the user is actualy see te tab. Problem is when the user clicks the tab the code is fired twice. (reloads etc is no problem).

 Edit: Oeps forget before and after de aspx...

Before the ASPX:

<%@ Page Language="VB" MasterPageFile="~/Beheer/MasterPage.master" AutoEventWireup="false"
    CodeFile="Deelnemer.aspx.vb" Inherits="Beheer_Deelnemer_Deelnemer" Theme="Blauw" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ MasterType VirtualPath="~/Beheer/MasterPage.master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:UpdatePanel ID="UpdatePanel" UpdateMode="Conditional" runat="server">
        <ContentTemplate>
            <asp:HiddenField ID="idHidden" Value="0" runat="server" />
            <asp:HiddenField ID="nieuwHidden" Value="False" runat="server" />
            <asp:HiddenField ID="wijzigingenHidden" Value="False" runat="server" />
            <div class="viewTitle">
                <asp:Label ID="viewTitelLabel" runat="server"></asp:Label>
            </div>
            <table width="100%">
                <tr>
                    <td rowspan="2">
After the ASPX:
  
                    </td>
                    <td class="menuTop">
                        <asp:Button CssClass="viewButton" ID="toevoegenButton" runat="server" OnClick="toevoegenButton_Click"
                            CausesValidation="False" />
                    </td>
                </tr>
                <tr>
                    <td class="menuBottom">
                        <asp:Button CssClass="viewButton" ID="terugButton" runat="server" OnClick="terugButton_Click"
                            CausesValidation="False" />
                        <asp:Button CssClass="viewButton" ID="wijzigButton" OnClick="wijzigButton_Click"
                            runat="server" CausesValidation="True"></asp:Button>
                    </td>
                </tr>
            </table>
            <asp:Button CssClass="viewButton" ID="navigeerEersteButton" Text="|<" runat="server"
                OnClick="navigatie_Click" CausesValidation="False" EnableViewState="false" />
            <asp:Button CssClass="viewButton" ID="navigeerVorigeButton" Text="<" runat="server"
                OnClick="navigatie_Click" CausesValidation="False" EnableViewState="false" />
            <asp:Button CssClass="viewButton" ID="navigeerVolgendeButton" Text=">" runat="server"
                OnClick="navigatie_Click" CausesValidation="False" EnableViewState="false" />
            <asp:Button CssClass="viewButton" ID="navigeerLaatsteButton" Text=">|" runat="server"
                OnClick="navigatie_Click" CausesValidation="False" EnableViewState="false" />
            <asp:Panel ID="alertPanel" runat="server" ScrollBars="Auto" Visible="false" CssClass="alertPanel"
                EnableViewState="false">
                <asp:ImageButton ID="alertImageButton" runat="server" CausesValidation="False" CssClass="alertButton"
                    EnableViewState="False" ImageUrl="~/App_Themes/Blauw/Sluiten.gif" OnClick="alertImageButton_Click" />
                <asp:ValidationSummary ID="viewValidationSummary" runat="server" ShowMessageBox="false"
                    ShowSummary="true" ValidationGroup="view" EnableViewState="false" Visible="false" />
                <asp:Label ID="alertLabel" runat="server" Visible="false"></asp:Label>
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
 
0
Benexx
7/18/2007 10:48:15 AM

Don't know why but if I select a different tab the OnActiveTabChanged fires twice and when I select the active tab it only runs once (don't even know if that's normal).

0
Benexx
7/18/2007 3:27:57 PM

 The problem happens when the TabContainer is inside the UpdatePanel. Here is a cleaner version that includes the problem.

I'll try to figure out how to solve it.

 

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    public static int count = 0;
    protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
    {
        count++;
        Label1.Text = count.ToString();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="3" OnActiveTabChanged="TabContainer1_ActiveTabChanged" AutoPostBack="True">
            <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="TabPanel1">
            </ajaxToolkit:TabPanel>
            <ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
            </ajaxToolkit:TabPanel>
            <ajaxToolkit:TabPanel ID="TabPanel3" runat="server" HeaderText="TabPanel3">
            </ajaxToolkit:TabPanel>
            <ajaxToolkit:TabPanel ID="TabPanel4" runat="server" HeaderText="TabPanel4">
            </ajaxToolkit:TabPanel>
        </ajaxToolkit:TabContainer>
            </ContentTemplate>
        </asp:UpdatePanel>
         
    </div>
         
    </form>
</body>
</html>
  
0
Raymond
7/19/2007 6:11:50 AM

My guess is that the event fires after an async postback (because it remembers the active tab and switches to that immediately), so it's firing once when the tab changes, and then again when the async postback completes.

A simple test for this would be to put a sleep statement in Page_Load on the server and observe if there's a time gap between the events firing.


Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
0
Steve
7/19/2007 6:36:12 AM

Hi Steve,

Both events fired after the page_load. So, can't see a time gap.

An interesting finding is that the stack trace of the events are different, one is rooted from TabContainer.IPostBackEventHandler.RaisePostBackEvent, the other one is from scriptControlBase.IPostBackDataHandler.RaisePostDataChangedEvent.
 

0
Raymond
7/19/2007 6:53:15 AM

Oh, sorry; I thought you were talking about the client-side event... now I see what you're saying!


Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
0
Steve
7/19/2007 8:18:01 AM

Raymond, please feel free to open a work item if you believe this to be a bug in the Toolkit. Thanks for the help!



http://blogs.msdn.com/Delay

This posting is provided "AS IS" with no warranties, and confers no rights.
0
David
7/20/2007 8:05:10 PM

 http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=11855

0
Raymond
7/23/2007 3:36:37 AM

I am having this same issue. Has anyone came up with a workaround?

0
ajaxdotnetnewbie
7/23/2007 9:35:43 PM
    Private temp As boolean = false
    Protected Sub viewTabContainer_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        If temp = false Then
            temp = true
'Code
End If End Sub
 
0
Benexx
7/24/2007 3:18:03 PM

Well, where do you reset the temp variable? In your case the event handler will execute the needed code only once. :)

I think there's no suited "workaround" for this problem, because one need to distinguish between the two root sources for the event raising, and this seems to be not possible...

Kind regards,

sbogus.

 

0
sbogus
7/24/2007 3:46:50 PM

 

    Private tempEenmalig As Boolean = True 'Tijdelijk ivm bug in Tabs

    Protected Sub viewTabContainer_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        'Deze code wordt om een vage reden 2 keer uitgevoerd. Post geplaats op ASP.net
        'http://forums.asp.net/p/1133367/1811883.aspx
        'Tijdelijk een tempEenmalig gebruikt.
        If tempEenmalig Then
            tempEenmalig = False
            checkView("tabs") 'Tab opnieuw opbouwen
        End If
    End Sub

This exacly my code to avoid the problem. After te postback te page wil reload and "Private tempEenmalig As Boolean = True" will run again and set to False so the code wil run once.
Works fine for me so don't know what your problem is...

0
Benexx
7/25/2007 10:57:31 AM
Use:  

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(viewTabContainer);

viewTabContainer will now act as a normal PostBackControl whether inside or outside an updatepanel

Disadvantage is a full postback.

 
0
arjanb83
5/5/2008 9:39:06 AM
Reply:

Similar Artilces:

TabContainer's "OnActiveTabChanged" event doesn't work properly
Hello,   I am writing an asp.net c# application with AJAX control toolkit. I am using a TabContainer with 2 tabs. Each of the tabs has a div inside, let's say: "div1" and "div2". When switching between the tabs I would like to show the relevant div with its relevant contents. The server side "Tabs_ActiveTabChanged" is fired. It tries to update the contents of the second div in the second tab by: div2.InnerHtml = "some text"; but nothing changes within this tab. What could be the reason for that? Thank you, Dana  ...

TabContainer's height doesn't respecting child GridView's height
Well, it's not that complex:I have a TabContainer with 4 tabs. In the first 2 I have different GridViews, but I'm actually only working with the first one.There's no UpdatePanel, no crazy situations, it's a simple GridView with an associated ObjectDataSource, wich will DataBind the GridView in every PostBack (yes, normal, simple, server-side PostBack) based on the value of a TextBox. And this value is only changed on the click of a ImageButton. All of this happens on the Server side.BUT, in the initial load of the page, the GridView is empty, as is the TabPanel. After the fir...

Replace 1's and 0's in a gridview column with Yes's and No's
Is it possible to change the display of a column in a gridview to show a Yes for all 1's and a No for 0's that display in a particular column of a gridview bound to a database?  If so, can someone share the way with me?  I am using ASP.NET 2.0 with VB Code Behind.  Thanks One way you can do is thrrough  CASE in your select statement: Select YesNoColumn= CASE yourColumn WHEN 1 THEN 'Yes' WHEN 0 THEN 'No' ELSE '' END FROM YourtableLimno <Columns>     <asp:TemplateField HeaderText="yourHeader" SortExpression="yourDataField"> ...

It's Linux !? No, it's BSD ! No, no, it's...
kFreeBSD http://wiki.debian.org/Debian_GNU/kFreeBSD a Debian distro using the FreeBSD kernel ! ObiWan wrote: > kFreeBSD > > http://wiki.debian.org/Debian_GNU/kFreeBSD > > a Debian distro using the FreeBSD kernel ! Why use a BSD kernel? I hope the reason is more than, just because they can. http://wiki.debian.org/Debian_GNU/kFreeBSD_why It's easy to understand why the would want to use Debian packages. :) -- Jimmy Johnson Registered Linux User #380263 >> kFreeBSD >> >> http://wiki.debian.org/Debian_GNU/kFreeBSD >> ...

Events fire's twice
Hi, at the moment i try to build a custom control with events but it looks like my events fire's twice so please help me. The code below will simulate my problem and is not the exacly code off my program.!!! this is the CONTROL code : namespace SampleControl : System.Web.UI.Control, IPostBackDataHandler, IPostBackEventHandler { public class EventExample { // events declaration public event EventHandler ButClick; protected virtual void OnBut1Click(EventArgs e) { if (ButClick != null) ...

superreview requested: [Bug 306437] change event fires twice for HTML select (mousedown & mouseup) : [Attachment 194591] Don't know how the UpdateSelection() call snuck in. It's clearly wrong.
Aaron Leventhal <aaronleventhal@moonset.net> has asked neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> for superreview: Bug 306437: change event fires twice for HTML select (mousedown & mouseup) https://bugzilla.mozilla.org/show_bug.cgi?id=306437 Attachment 194591: Don't know how the UpdateSelection() call snuck in. It's clearly wrong. https://bugzilla.mozilla.org/attachment.cgi?id=194591&action=edit ...

superreview granted: [Bug 306437] change event fires twice for HTML select (mousedown & mouseup) : [Attachment 194591] Don't know how the UpdateSelection() call snuck in. It's clearly wrong.
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has granted Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 306437: change event fires twice for HTML select (mousedown & mouseup) https://bugzilla.mozilla.org/show_bug.cgi?id=306437 Attachment 194591: Don't know how the UpdateSelection() call snuck in. It's clearly wrong. https://bugzilla.mozilla.org/attachment.cgi?id=194591&action=edit ------- Additional Comments from neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> I'm not a layout peer but t...

IBM's WebSphere vs. MS's .NET (article)
http://www.osopinion.com/perl/story/16270.html "Unlike Microsoft's model, which only allows Windows applications to communicate with other Windows applications, WebSphere is committed to an open source environment. " -- JB Learn the Hazards http://www.staff.uiuc.edu/~ehowes/info17.htm ...

Mozilla get's no style tag's from .net server.
I made a webform in web matrix, and it looks fine in IE. If I open the same link whit Mozilla, it looks like a disaster. When I look at the HTML source, there are no style tags as in IE. But when I save the HTML source from IE (the one whit style tags) and open it in Mozilla, it looks perfect. So the onley reason the webform looks wrong in Mozilla, is because the .net server detects Mozilla and not IE and sends a style less HTML source. Wy? Mozilla does support style tags. Is there a solution for this bug? Or is this a uh.. feature? ..Mivz Update, I have got some more info. It is ...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

TabContainer's ActiveTabChanged event does not fire
I have a page that uses the AjaxControlToolkit's TabContainer. However, when clicking a tab the ActiveTabChanged event is not triggered. This is a big problem because in order to display the correct and most recent data in the selected tab code must be executed when the tab is selected. I have found the OnClientActiveTabChanged and tried to use Me.ClientScript.GetPostBackEventReference() with it, but it keeps giving me errors. Does anybody know a simple way to have the ActiveTabChanged event triggered every time you switch tabs? Thanks.--Nathan Sokalskinjsokalski@hotmail.comhttp://www.na...

Why would a control's event be fired twice?
I've encountered a strange problem that I can't figure out.  Could you take a quick look at this image.  The uppermost textbox is called 'textBoxDescription'.  When I change the value in it and click on one of the controls below it then everything works as it should; namely its TextChanged event is fired and certain housekeeping is taken care of. But when I change the value in it and click on the treeview on the left then TextChanged is actually fired TWICE.  I see what's happening but don't understand why it's happening.  I'm hoping t...

Hyperlink's, ImageURL's, and OnError's
I created an ASP:Hyperlink and set the ImageURL attribute so the link will be the image.If the image is missing, I would like it to display a 'missing image' pic that I have.  I know you can use the OnError attribute of the <img> tag to run some javascript to change it.Unfortunately I can't find a way to access the Hyperlink's Image that is inside it, so I can add an Attribute so the resulting <img> tag will have an OnError attribute inside of it.Any help?If my Hyperlink is called 'foo'....would I do...  ((Image) foo.Controls[0]).Attributes.Add(&...

Net security is everyone's problem not just Microsoft's, says Ballmer
Speaking at the Center for Strategic and International Studies in Washington DC, Microsoft chief executive Steve Ballmer declared that responsibility for cybersecurity falls on everyone---users, software vendors, and government agencies. Mr. Ballmer did not outline any new security initiatives, but continued to promote the upcoming Windows XP Service Pack 2, an update to the company's server operating system, and future versions of Internet Explorer that will block pop-up ads and unauthorized downloads. Mr. Ballmer outlined active protection technology, designed to stop worms...

Web resources about - tabContainer's OnActiveTabChanged fires twice - asp.net.ajax_control_toolkit

Resources last updated: 12/15/2015 1:14:43 AM