473,503 Members | 3,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event getting called 2 times indside an Update Panel.

7 New Member
I had a question on updatepanel. I had a simple form where I had one update panel.It contains a tab container which
contains 3 tabs.Now I had set auto-postback of this container to true.I am not able to understand why my activetabchanged
event is being called 2 times.Normally as is the case with server controls,it should be called only once.The code is given below:
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" runat="server">
  2.     <div>
  3.         <asp:ScriptManager ID="ScriptManager1" runat="server">
  4.         </asp:ScriptManager>
  5.  
  6.         <asp:UpdatePanel ID="UpdatePanel1" runat="server" EnableViewState="False">
  7.             <ContentTemplate>
  8.                 <cc1:tabcontainer id="TabContainer1" runat="server" activetabindex="2" autopostback="True"
  9.                     onactivetabchanged="TabContainer1_ActiveTabChanged" width="600px"><cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1"><HeaderTemplate>
  10. home
  11. </HeaderTemplate>
  12. </cc1:TabPanel>
  13. <cc1:TabPanel runat="server" HeaderText="TabPanel2" ID="TabPanel2"><HeaderTemplate>
  14. settings
  15. </HeaderTemplate>
  16. </cc1:TabPanel>
  17. <cc1:TabPanel runat="server" HeaderText="TabPanel3" ID="TabPanel3"><HeaderTemplate>
  18. Analysis
  19. </HeaderTemplate>
  20. </cc1:TabPanel>
  21. </cc1:tabcontainer>
  22.             </ContentTemplate>
  23.         </asp:UpdatePanel>
  24.  
  25.     </div>        
  26.     </form>
  27. Code behind code is :
  28. public partial class Test2 : System.Web.UI.Page
  29. {
  30.     protected void Page_Load(object sender, EventArgs e)
  31.     {
  32.  
  33.     }
  34.     protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
  35.     {
  36.         Thread.Sleep(4000);
  37.         //Do some processing herer.
  38.     }
  39. }
Nov 16 '07 #1
5 10785
terminul
6 New Member
Hi Rawat,

This is apparently an issue/bug with the Ajax Control Toolkit, as yet there is no resolution. People are getting the same problems as you are, there is however a workaround.

This bug is currently lodged at http://www.codeplex.com/AtlasControl...rkItemId=11855

The workaround is simple enough, apparently the bug is caused by 2 post back events being raised separately, once by asp ajax and once by the toolkit itself.
I'm vaguely sure about this but the work around is here.

in your code behind

where u had
Expand|Select|Wrap|Line Numbers
  1. protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
  2.     {
  3.         Thread.Sleep(4000);
  4.         //Do some processing herer.
  5.     }
  6.  
just add a private bool set it to true (or u can reverse the logic - set it to false then within the ActiveTabChanged change it to true). and all u have to do is encapsulate the code u want to perform within the if statement

Expand|Select|Wrap|Line Numbers
  1. private bool isPageLoaded = true;
  2. protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
  3.     {
  4.         if (isPageLoaded)
  5.         {
  6.             isPageLoaded = false;
  7.             Thread.Sleep(4000);
  8.             //Do some processing herer.
  9.         }        
  10.     }
  11.  
CAVEAT: I don't think this workaround actually stops double posting, just merely lets ur code run once instead of twice
Nov 17 '07 #2
rawatgaurav81
7 New Member
Hi Terminul,
Thanks for the reply....yeah i am already doing that in my application.But my application is a bit complex so using a private variable would not suffice because everytime a page is requested the variable would be initialized to its intial value and using static variables in a web application is always risky so I had to contend with a session variable to maintian its values across requests.
Hope micrososft fix this bug

Cheeeeerssss
Gaurav
Hi Rawat,

This is apparently an issue/bug with the Ajax Control Toolkit, as yet there is no resolution. People are getting the same problems as you are, there is however a workaround.

This bug is currently lodged at http://www.codeplex.com/AtlasControl...rkItemId=11855

The workaround is simple enough, apparently the bug is caused by 2 post back events being raised separately, once by asp ajax and once by the toolkit itself.
I'm vaguely sure about this but the work around is here.

in your code behind

where u had
Expand|Select|Wrap|Line Numbers
  1. protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
  2.     {
  3.         Thread.Sleep(4000);
  4.         //Do some processing herer.
  5.     }
  6.  
just add a private bool set it to true (or u can reverse the logic - set it to false then within the ActiveTabChanged change it to true). and all u have to do is encapsulate the code u want to perform within the if statement

Expand|Select|Wrap|Line Numbers
  1. private bool isPageLoaded = true;
  2. protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e)
  3.     {
  4.         if (isPageLoaded)
  5.         {
  6.             isPageLoaded = false;
  7.             Thread.Sleep(4000);
  8.             //Do some processing herer.
  9.         }        
  10.     }
  11.  
CAVEAT: I don't think this workaround actually stops double posting, just merely lets ur code run once instead of twice
Nov 19 '07 #3
ashar09
2 New Member
Hi I got similar issue of getting dual postback on ActivetabChanged .

WorkAround:
1- set Autopostback to False;
2- Set the TabChanged event like this :
Expand|Select|Wrap|Line Numbers
  1.     <ajaxToolkit:TabContainer ID="tabAllowBlock" runat="server"   
  2.                        AutoPostBack="false" 
  3.                        ScrollBars="Auto" 
  4.                        ActiveTabIndex="0"   
  5.                        OnClientActiveTabChanged="LoadAllowBlock" 
  6.                        OnActiveTabChanged="tabAllowBlock_ActiveTabChanged"  >
  7.  
3-Write a javaScript Function LoadAllowBlock() in my case :
Here u can casue a postback such tat tabAllowBlock_ActiveTabChanged
gets fired.
This is how i Did :

Expand|Select|Wrap|Line Numbers
  1. function LoadAllowBlock() {
  2.     __doPostBack('ctl00_BodyContentMid_tabAllowBlock', '');
  3. }
__doPostback requires the Client ID of the TabContainer.

4- write ur logic in Code Behind for Tabchange

Expand|Select|Wrap|Line Numbers
  1. protected void tabAllowBlock_ActiveTabChanged(object sender, EventArgs e)
  2.         {
  3.             if (tabAllowBlock.ActiveTabIndex == 0) 
  4.             {
  5.                 //your Code
  6.              }
  7.             else   
  8.             {
  9.                //your Code 
  10.             }
  11.  
  12.  
  13.         }
Hope it Resolves the Issue :)
Any queries If any can revert back at:<email removed>
Oct 9 '09 #4
altafbytes
2 New Member
Hi,

Your solution is good it's working fine.
But i am using it in child page(Of MasterPage) .
the event TabContainer1_ActiveTabChanged is not getting fire.

thanks in advance.
Oct 16 '09 #5
ashar09
2 New Member
Make sure u have added it to the attribute "OnActiveTabChanged" for the TabContainer .
Oct 16 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2191
by: rodchar | last post by:
hey all, how can i get javascript procedure to execute as the very last thing before the page is rendered? Background: I have a DIV element inside an update panel. I am setting the scrollLeft...
2
4931
by: rodchar | last post by:
hey all, i saw an update panel example one time where they put a button outside the update panel and a textbox inside the panel and setup a trigger on the update panel to update when the button...
2
2357
by: DanWeaver | last post by:
I have a page where layout of buttons and listboxes etc is important - I would like to make use of Ajax Update panel to asynchronously update various part of the page- in Vis studio whenever I use...
1
9144
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a...
0
2103
by: hetalupadhyay | last post by:
hi i take one update panel nd put inside gridview when i click print button no operation perform and when i remove update panel then it work perfectly so wht i do?.................to solve this ...
1
1914
by: sweatha | last post by:
I have designed the login form with 3 panels. In the first panel I have the login verification such as login id, password, login button and forgot password link button. In the second panel I have...
4
3469
by: karthik25 | last post by:
Hi All, I have a problem in finding control in a dynamically created updated panel. I have given the code below. Following is just a starting effort in a completely dynamic user control. I am...
2
5684
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
4
3710
by: SAL | last post by:
Hello, I'm working, basically my first, AJAX page and am having a few problems. One is that the Click event for a button I have in UpdatePanel1 is not getting called. I've tried with the button...
0
7063
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4663
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
366
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.