Showing posts with label __dopostback. Show all posts
Showing posts with label __dopostback. Show all posts

Saturday, March 24, 2012

TabContainer + ActiveTabChanged + __doPostBack Problem

I have a tabcontainer that i want to postback only when certain tabs are clicked (lets call them "postback tabs")

Here is the setup:

<ajax:UpdatePanel ID="upOuter" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<act:TabContainer ID="TabContainer1" runat="server" CssClass="MyTabStyle" ActiveTabIndex="0" OnClientActiveTabChanged="ActiveTabChanged">
....
....

<script language="javascript" type="text/javascript"
function ActiveTabChanged(sender, args) {
var ht = sender.get_activeTab().get_headerText();
if ((ht =="TabHeader1") || (ht =="TabHeader2") || (ht =="TabHeader3") ){
__doPostBack('<%= tabcontainer1.ClientID %>', sender.get_activeTab().get_headerText());
}
}
....
....

Server Side:

Protected Sub TabContainer1_ActiveTabChanged(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles TabContainer1.ActiveTabChanged

If TabContainer1.ActiveTab.HeaderText = "TabHeader1"Then
....
....
End If
If TabContainer1.ActiveTab.HeaderText = "TabHeader2"Then
....
....
End If
If TabContainer1.ActiveTab.HeaderText = "TabHeader1"Then
....
....
End If
End Sub

This actually works quite well except in the following case:

Step 1. I click on one of the postback tabs

Step 2. Click on a non-postback tab

Step 3. Click back on the tab from step 1.

When I do this, the client side script runs, but the postback never happens. If on step 2, i clicked on a postback tab, everything works fine. Or, if on step three I click on a different postback tab than in step 1, everything works fine.

Any ideas?

Figured out the problem. The postback IS happening, but the server-side activetabchanged event was not firing. The reason for this is that when I clicked on a non-postback tab, the server was not notified of the change in activetab. So, following the steps in the original post, when I click back on to the postback tab in step 3 (the same as the postback tab in step 1), the server thinks the active tab is still the same - since it was not notified of the change in step 2. Hence, ActiveTabChanged does not fire on the server-side.

Wednesday, March 21, 2012

TabContainer Lag when loading controls by __doPostBack in OnClientActiveTabChanged

I am using a tabContainer on my web. My final product is a TabContainer nested inside of another TabContainer, but the latency is static between the two scenarios.
Here is a sample of my code:

 
 <script type="text/javascript"> function ActiveTabChanged2(sender, e) { __doPostBack(sender.get_id(), sender.get_activeTab().get_headerText()); } </script>

Container =new TabContainer(); Container.ID ="Container"; Container.OnClientActiveTabChanged ="ActiveTabChanged2"; Container.ActiveTabChanged +=new EventHandler(ActiveTabChangedServer); Container.CssClass ="ajax__tab_gray";public void ActiveTabChangedServer(object sender, EventArgs e) {string ID =""; TabContainer tab = (TabContainer)TabContainer1.ActiveTab.FindControl("Container"); TabContainer BottomTab = (TabContainer)tab.ActiveTab.FindControl("Container2"); ID = BottomTab.ActiveTab.ID.Substring(4); UpdatePanel Upd = (UpdatePanel)BottomTab.ActiveTab.FindControl("upTab_List"); Upd.ContentTemplateContainer.Controls.Add(new LiteralControl("test")); }

Now, everything functions properly with my scriptmanager catching the postback and rerouting it to an async, etc.

The problem is, there is 2 seconds where the server and client is doing absolutely nothing before it will write "test" in my updatepanel.

No matter what scenario I use, everything loads fine, the async postback is rerouted, but then after that there is 2 seconds of nothing before the text is written, as if I were to do a thread.sleep

any help would be much appreciated as this is a main part of my corporate intranet site and I would love to keep ajax as a part of that site, but 2 seconds on top of every loadtime is leading people to beleive the resource is broken as they click from tab to tab quickly with a blank page underneath each.

Thanks,

Brandon Schoen
Netlist
Sr. .Net Architect
www.netlistinc.com

0 replies... does this mean I am the only person to experience this issue?