views:

90

answers:

2

Hi All,

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.

+2  A: 

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;
}
Nick Craver
private override void OnLoad(EventArgs e) and speed: <%=Speed %> showing error.
Geetha
@Geetha - Try it now....it was late and I forgot OnLoad was protected and not private :)
Nick Craver
+2  A: 

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.

jerjer
i am getting this error Error 2 '_Default.OnLoad(System.EventArgs)': virtual or abstract members cannot be private
Geetha
Shall i try this code in page load event.
Geetha
just replace private to protected on the Onload method
jerjer