JQuery Carosellite and cycle and parameter from c#
I am using jquery Carosellite and Cycle to display images like frames. How to pass values to the properties like speed, visible ect from codebehind(c#).
Ex html code:
<script type="text/javascript" language="javascript">
$(function() {
$(".anyClass").jCarouselLite({
btnNext: ".next",
btnPrev: ".prev",
visible: 1,
scroll: 1,
speed: 1000
});
});
</script>
开发者_开发技巧
Geetha.
If you don't like mixing ASP.NET code your mark-up you could also do this:
markup:
<asp:HiddenField runat="server" id="hfVisible" Value="true" />
<asp:HiddenField runat="server" id="hfSpeed" Value="1000" />
javascript:
$(function() {
$(".anyClass").jCarouselLite({
btnNext: ".next",
btnPrev: ".prev",
visible: $('#hfVisible').val(),
scroll: 1,
speed: $('#hfSpeed').val();
});
});
code behind:
protected override void OnLoad(EventArgs e) {
hfVisible.Value = true;
hfSpeed.Value = 1000;
}
Note: if the HiddenFields are on a UserControl do not use the id to reference the elements, use class instead, or another attributes; or to avoid this: use the RegisterHiddenField:
ClientScriptManager cs = Page.ClientScript;
// Register the hidden field with the Page class.
cs.RegisterHiddenField('hfVisible', "false");
cs.RegisterHiddenField('hfSpeed', "1000");
In this way, you don't need to declare HiddenFields in the markup.
If the properties are in the codebehind, you can stick them in the page for a quick solution:
$(function() {
$(".anyClass").jCarouselLite({
btnNext: ".next",
btnPrev: ".prev",
visible: <%=Visible %>,
scroll: 1,
speed: <%=Speed %>
});
});
In the page:
protected int Visible { get; set; }
protected int Speed { get; set; }
protected override void OnLoad(EventArgs e) {
Visible = 1;
Speed = 1000;
}
精彩评论