JQuery Carosellite and C # loop and parameter

I am using jquery Carosellite and Cycle to display images like frames. How to pass values ​​to properties such as 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>

Gita.

+3
source share
2 answers

If you don't like mixing ASP.NET code with your label, you can 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 HiddenFields are in UserControl, do not use an identifier to refer to elements, use a class instead or other attributes; or to avoid this: use RegisterHiddenField:

ClientScriptManager cs = Page.ClientScript;
// Register the hidden field with the Page class.
cs.RegisterHiddenField('hfVisible', "false");
cs.RegisterHiddenField('hfSpeed', "1000");

This way you do not need to declare HiddenFields in the markup.

+2
source

, :

$(function() {
    $(".anyClass").jCarouselLite({
        btnNext: ".next",
        btnPrev: ".prev",
        visible: <%=Visible %>,
        scroll: 1,
        speed: <%=Speed %>
    });
});

:

protected int Visible { get; set; }
protected int Speed { get; set; }

protected override void OnLoad(EventArgs e) {
  Visible = 1;
  Speed = 1000;
}
+2

Source: https://habr.com/ru/post/1730964/


All Articles