c# - Using Javascript inside a dynamically load UserControl in jQuery Ui Tabs -
i need insert javascript code inside usercontrol load ajax call via jquery ui tabs. let me explain...
this view (with jquery loaded)
<script type="text/javascript"> $(document).ready(function () { $("#tabs").tabs({ cache: false, }); getcontenttab (1); }); function getcontenttab(index) { var url='<%= url.content("~/home/getusercontrol") %>/' + index; var targetdiv = "#tabs-" + index; $.get(url,null, function(result) { $(targetdiv).html(result); }); } </script> <div id="tabs"> <ul> <li><a href="#tabs-1" onclick="getcontenttab(1);">nunc tincidunt</a></li> <li><a href="#tabs-2" onclick="getcontenttab(2);">proin dolor</a></li> <li><a href="#tabs-3" onclick="getcontenttab(3);">aenean lacinia</a></li> </ul> <div id="tabs-1"> </div> <div id="tabs-2"> </div> <div id="tabs-3"> </div> </div>
with these lines of code call ajax function load content div. action controller:
public actionresult getusercontrol(int num) { return partialview("testuc", num); }
and usercontrol...
<%@ control language="c#" inherits="system.web.mvc.viewusercontrol" %> number... <span id="testspan"><%=model.tostring() %></span>!! <input type="button" value="click me!!" onclick="message();" /> <script type="text/javascript"> function message(item) { alert($("#testspan").html()); } </script>
the problem message() function returns 1 (instead of returning correct number).
my question is... how should add script usercontrol in order have code running correctly?
i'm guessing here.
i guess problem when tab loaded, stays in dom if open 1 (i.e. if #1 default, remain loaded if click on second one).
if happening, when call message function, there multiple elements id "testspan", , jquery selector $("#testspan") return first of them.
i suppose test code, particular case go adding <%= model.tostring() %> argument javascript function.
again, i'm guessing behavior of jquery-ui tabs() function.
regards
Comments
Post a Comment