Forum Moderators: open

Message Too Old, No Replies

setting active tab in ajax tabcontainer using javascript

setting active tab in ajax tabcontainer using javascript

         

tomn99

11:27 pm on May 25, 2011 (gmt 0)

10+ Year Member



hi anyone,

i'm trying to set a specific tab in an ajax tabcontainer. i get this javascript error: "null is null or not an object line 15 (referring to the line where i call "set_activeTabIndex":

i've looked all of the web and still no luck, any help wold be apreciated.



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<link rel="stylesheet" href="../include/textstyle.css" type="text/css">
<script language=javascript>

function MoveTab(num)
{
var ctrl = $find('TabContainer1');
ctrl.set_activeTabIndex(1);
}
</script>
</head>
<body onload="javascript:MoveTab('1');">
<form id="form1" runat="server">
<asp:ScriptManager runat=server ID=scriptmanager>
</asp:ScriptManager>
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" Height="350px">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server" >
<HeaderTemplate>
one
</HeaderTemplate>
<ContentTemplate>
111111111
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" >
<HeaderTemplate >
two
</HeaderTemplate>
<ContentTemplate>
22222
</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel3" runat="server"
HeaderText="three">
<ContentTemplate>
33333
</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
</form>
</body>
</html>

JAB Creations

5:56 am on May 27, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



alert(typeof my_id_or_javascript_object);


When something is null it usually doesn't exist.

Don't use any attributes on the body element, use an anonymous function with the onload event...

window.onload = function()
{
do_something1();
do_something2();
do_something3();
}


Also don't use dollar signs with JavaScript variables, you use var to declare variables initially though don't have to use them to assign a second value...

example()
{
var a = 0;
a = 1;
alert(a);
}


Whoa, I highly advise reconsidering what you're coding here with the proprietary Microsoft junk and it is junk. I bought an ASP.NET book years ago and it suggested using ASP.NET code to generate code that looked something like HTML if say you put HTML threw a paper-shredder. Your code will not validate and if you go down that path you'll seriously make yourself a burden to clients or potential employers.

Also there is no language attribute on script elements. I don't know where you're learning all this non-code from though you need to seriously look elsewhere.

Fix those issues, validate your code as XHTML Strict 1.0 with the W3C validator. Here is a template for you to work with...really get out of working on Microsoft code and with IIS servers, it's REALLY not the way to go unless you're living in an M$ dominated city for some reason. Even then you should totally cut down on the very poor coding practices they promote. Here is a template for you...

- John

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Example</title>
<base href="http://localhost/project_subdirectory/" />
<link rel="stylesheet" href="textstyle.css" type="text/css" />
<script type="application/javascript">
//<![CDATA[

/*
Your scripts go here for test, in a separate file for live environments for cache.

Keep your onload event and global variables in a separate onload.js file, all other scripts in index.js
*/

window.onload = function()
{
alert('oh hai!');
alert(document.getElementById('input_id1').value+'\n\n'+typeof document.getElementById('input_id1'));

//do_something1();
//do_something2();
//do_something3();
}

//]]>
</script>
</head>

<body>

<form action="/" method="post">
<fieldset>
<div><label for="input_id1">label text</label><input id="input_id1" name="input_id1" type="text" value="11aa" /></div>
<div><label for="input_id2">label text</label><input id="input_id2" name="input_id2" type="text" value="22bb" /></div>
<div><label for="input_id3">label text</label><input id="input_id3" name="input_id3" type="text" value="33cc" /></div>
</fieldset>
</form>

<div><p>Use the base element in conjunction with any href and src attributes, in example <a href="example1/">example</a>.</p>

</body>
</html>