Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a java script:

JavaScript
<script type="text/javascript">

    function mycarousel_initCallback(carousel) {
        // Disable autoscrolling if the user clicks the prev or next button.
        carousel.buttonNext.bind('click', function () {
            carousel.startAuto(0);
        });

        carousel.buttonPrev.bind('click', function () {
            carousel.startAuto(0);
        });

        // Pause autoscrolling if the user moves with the cursor over the clip.
        carousel.clip.hover(function () {
            carousel.stopAuto();
        }, function () {
            carousel.startAuto();
        });
    };

    jQuery(document).ready(function () {
        jQuery('#mycarousel').jcarousel({
            auto: 2,
            wrap: 'last',
            initCallback: mycarousel_initCallback
        });
    });
   
</script>


This java script is put in master page and i want to call this java script in drop down selected index changed, dropdown is placed in user control So how can i do this plz help me
Posted
Updated 23-Dec-12 18:31pm
v2
Comments
bbirajdar 24-Dec-12 0:38am    
use the 'onchange' client side event of dropdown to call the javascript
Arun kumar Gauttam 24-Dec-12 0:44am    
sir plz put eject line then how i call "function mycarousel_initCallback(carousel)" and i pass "carousel" in that function, because with out parameter function is call easily,

Hi Arun,

Try using Response.Write() method for this but before this please ensure that the JS file is referenced properly in the output HTML.

JavaScript
Response.Write("<script>mycarousel_initCallback(carousel);</script>");




Hope this helps.
Happy Coding :)
 
Share this answer
 
v2
In your code behind write as below.


C#
protected void Page_Load(object sender, EventArgs e)
    {
        ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
        if (!Page.IsPostBack)
        {
            ddl.Attributes.Add("onchange", "mycarousel_initCallback(ddl);");
        }
    }

    protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
       //Your Code
    }


And your ASPX will be like:
XML
<asp:DropDownList ID="ddl" runat="server"  AutoPostBack="true">
        <asp:ListItem Text="a" Value="a"></asp:ListItem>
         <asp:ListItem Text="b" Value="b"></asp:ListItem>
        </asp:DropDownList>
 
Share this answer
 
Hi,

You can also do like this:

You can add the
C#
onchange="yourfunctionname()"
code to the dropdown and add the function in the script tag in the begining.

This is the best way to do...

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900