Problem with causing a postback in one tab from another Tab's onload() event

pinTab

Problem with causing a postback in one tab from another Tab's onload() event


AndrewC 02-26-2007, 7:16
Hi-

I have another issue that I hope you can help me with.

Here is the situation. I have a page- call it "main page" - that derives from an ASP.NET 2.0 Master page. It hosts a PinTab control.

On Tab 7 and Tab 8, I have pages that need to change the Text of their Tab according to a value in a hidden field on the page. This occurs via a JavaScript function in the Head of the document which is called in the body tag's On_Load() event. The code in that function looks like this (example taken from Tab 8):
function changeTabTitle()
{
var value = document.getElementById("NameOfHiddenField").value;
var item = parent.objTab.getTabItemByIndex(8);

item.setText("Stock(" + value + ")");
}


So far so good; this all works.

The issue is in the next part: on several of the other Tabs, I have an ASP.NET FormView control that pulls records from a database. I need for the pages on Tab 7 and Tab 8 to change their Tab's .Text, using the function above, every time the user Pages through the data in the FormView; in other words, when the user moves from one record to another in Tab 1-Tab 6, I need to reload Tab 7 and Tab 8, which will call the above function to change the Tab's .Text. Incidentally, I have server-side code which keeps the records on Tab 7 and Tab 8 in sync with the records on the other pages. This code also runs on PostBack.

The approach I have taken is to create the following JavaScript function in the Head of Tabs 1-6:

function initPostBack
{
parent.objTab.getTabItemByIndex(7).netPostback();
parent.objTab.getTabItemByIndex(8).netPostback();
}

This function is called in the body onload() event of Tabs 1-6. This should take care of my needs, as Paging through the data in any one of Tabs 1-6 causes that Tab's page to re-load. That should call my function, which should then cause Tabs 7 and 8 to reload/Post Back, thus firing my code to change their .Text.

The problem is that, while it all works, it works very erratically. Most of the time, Tabs 7 and 8 don't change their .Text. I added a client-side button to Tab 1 that does nothing but cause Tabs 7 and 8 to Post Back; then I experimented with Paging through the data. Often, when Paging doesn't cause Tabs 7 and 8 to change their .Text, clicking the button does cause the Text to change; however, it often takes 2 clicks of the button!

I have verified that my function on Tabs 7 and 8 is being called, by adding an alert(). The alert is fired every time, as it should be. But for some reason, the rest of the code, which changes the .Text property of the Tab, doesn't appear to run successfully, and the .Text doesn't change; or it changes sometimes, but not most of the time.

I have to wonder if this issue is somehow related to either the fact that the PinTab control is hosted on a page derived from a MasterPage, or a timing issue where the objTab object is not created soon enough, or a combination of both.

Do you have any idea what the problem could be?


Thanks,

-Andrew

Re: Problem with causing a postback in one tab from another Tab's onload() event


Pintexx Support 03-02-2007, 11:21
Hi Andrew,

this might be a timing problem.
Could you please try this:

In onload do not call "changeTabTitle" directly but use:

setTimeout("changeTabTitle()",200);

Does this help ?

Regards,
Hans-Peter

Re: Problem with causing a postback in one tab from another Tab's onload() event


AndrewC 03-02-2007, 6:38
It's very odd.

I set the Timeout. Nothing happened; still not working. I took it out, then I stepped through the code in the MS Script Debugger and it worked. This indicated to me that it MUST be a timing issue. I put the setTimeout() back in the code, with a TimeOut of 5000. It worked. I gradually reduced the Timeout down to 200, and it still worked. Then I removed the Timeout, and it still worked! At least for 3 or 4 tests, then it failed again.

I am hoping the setTimeout() will fix it, but I won't know for sure until I can upload it to the server and test it there. I have a suspicion that the Personal Web Server that comes with Windows XP, which I use for development and initial testing, has timing bugs in it.

I'll let you know the results. Thanks for the help.

-Andrew

Re: Problem with causing a postback in one tab from another Tab's onload() event


AndrewC 03-12-2007, 5:26
Hans-Peter-

I am still seeing some inconsistent behavior from PinTab. I have eliminated the JavaScript on the other pages that calls the .NetPostback on the page where I want to change the text of the Tab, and am now relying just on the built-in "reload all Tabs when one reloads" behavior. It seems to work a bit better, but not yet where I need it to be. I will continue working on it when I can.

By the way, I have noticed some odd behavior when using a JavaScript debugger on the pages with the PinTab control. It happens both with the free add-in Firebug debugger for FireFox, as well as the MS Script Debugger in I.E.

Here is what I am seeing: as the PinTab and the child Tab control pages reload, the debugger always stops at a place in the PinTab.js file where I have NOT set a breakpoint, indicating an error. It stops at the same point in the PinTab.js file for every tab, though usually I don't see it stop for all 7 tabs every time. Often it happens when the first tab is reloading; sometimes I see it stop at the same point for 3 or 4 pages in one reload.

The place it stops is in the "tab_doc_loaded(index,name)" function. If you expand the function to place one statement on each line, and place each bracket { on its own line, the line it stops on would be line 27. The statement on that line is this:

parent.tabEventPageLoaded(item, controlID);

after that, when continuing to step through the code in the debugger, the program flow goes to the catch{} block immediately below, so obviously there is an error. Looking at the values of the different parts of the statement, I notice that "parent.tabEventPageLoaded" is undefined. Also, the debugger indicates that "allLoaded" is undefined as well.

Occasionally, it will also stop in the section below: under the "if(!browser.opera)" section, there is a section that starts "if(allLoaded)". In that section, at the line "parent.tabEventLoaded(controlID)", it stops, and indicates that tabEventLoaded is undefined. parent.TabEventLoaded is also undefined, though controlID does have a value, of "ctl00_ContentPlaceHolder1_Pintab1".

I notice if I comment out the Try/Catch lines, I get the error "parent.tabEventPageLoaded is not a function" in FireFox; IE gives me the error
"object doesn't support this property or method".

I can't help but wonder if these errors are related to either this problem, or the problem I am having getting Safari to recognize that the Tabs are clickable.

Any thoughts on this?

Thanks again...

-Andrew