views:

74

answers:

2

Hi i have a MasterPage (ASP.Net MVC) which contains a couple of loads for Jquery ui and under that a contentplaceholder for view specific scripts:

<script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="../../Scripts/ui.core.js" type="text/javascript"></script>
<script src="../../Scripts/ui.tabs.js" type="text/javascript"></script>
<script src="../../Scripts/ui.accordion.js" type="text/javascript"></script>
<script src="../../Scripts/LeftNav.js" type="text/javascript"></script>
<asp:contentplaceholder id="Scripts" runat="server"></asp:contentplaceholder>

Now I made a view which contains this script

<asp:Content ID="Content2" ContentPlaceHolderID="Scripts" runat="server">
<script>
var $tabs = $('#tabs').tabs();$tabs.tabs('option', 'selected', <%= ViewData["tab"]%>) ;
location.href='#<%= ViewData["anchor"]%>';
</script>
</asp:Content>

tha value in tab is the tabindex which should be selected. the anchor is a anchor on the tabpage which should be selected.

My suggestion was that first all Master scripts load than the tabindex I saved in the ViewData will selected and than I jump to the anchor i wanted to.

But how could it else be... nothing happens.

The side loads and the tabs too. But not the tab in the ViewData propertie tab is selected. and than the anchor cant work annyway.

I tried following. I put a alert in the script above and if I do that the alert is thrown before the tabs are load. Why does he exectue this script before loading the ui.script`???????????

+6  A: 

I'm not sure if I got that all right and I don't know nothing about asp, but maybe you should checkout jquery's ready event, which is triggered when the page is loaded. That might get you out of timing problems.

Tim Büthe
perfect it works thanks!
Markus
A: 

put your script at the bottom of the page ... that is before the </asp:Content> that way ur script will load after all the content has loaded ... if not write down the exact error ur getting ... as suggested above u can also use the $(document).ready

lucky