in my asp.net project I have a panel and on it a jquery tabs div. Initially the panel is hidden and it is shown if I click a button.
This is the very simple code:
<div id="tabs">
<ul id="none">
<li><a href="#tabs-1">Asset details</a></li>
<li><a href="#tabs-2">Structure details</a></li>
<li><a href="#tabs-4">Audit Info</a></li>
</ul>
<div id="tabs-1">Some Content for tab 1</div>
<div id="tabs-2">Some Content for tab 2</div>
<div id="tabs-3">Some Content for tab 3</div>
</div>
And jquery code:
function myfunction() {
$("#tabs").tabs();
}
The problem is that when I show the panel the tabs div is visible but not formatted.
All run correctly if I set a delay on myfunction:
function myfunction() {
//$("#tabs").tabs();
setTimeout(function () {
$("#tabs").tabs();
}, 500);
}
Is there a way to solve this problem in a more secure way?
Here the missing code:
The button that show my panel on click:
<my:RoundedButton ID="BillingDataButton" runat="server"
SkinID="Small"
Text="Billing data"
OnClick="BillingDataButton_Click"
/>
Code behind:
protected void BillingDataButton_Click(object sender, EventArgs e)
{
BillingDataPanel.Show();
}
I've tryed this (thanks Michael):
$(document).ready(function() {
$("#tabs").tabs();
});
But when I click my button and panel is shown the result is:
Update - A possible solution
Added this code in my asp.net page:
<script type="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function (s, e) {
myfunction();
});
This ensures that the jquery code for displaying the tab is executed at the end of the request. No setTimeout is requested in this case.
Please inform me if exixt a better solution.