1

I know this question has been asked quite a bit, but nothing seems to work for me. I've read many questions and answers.

I'm using a JQuery event to handle the event of an ASP.NET control, but the event will not fire.

This is what I've tried:

My DropDownList:

<asp:DropDownList ID="List_ValueStream" runat="server" Width="195px" />

My attempts to add events to the DropDownList, all tested separately:

in:

    <script src="http://code.jquery.com/jquery.min.js" type="text/javascript">
          ...
    </script>

/

    $(document).ready(function () {
        $("#<%=List_ValueStream.ClientID%>").change(function () {
            alert('1 Handler for .change() called.');
        });
    });

/

    $(document).ready(function () {
        $("#List_ValueStream").change(function () {
            alert('2 Handler for .change() called.');
        });
    });

/

    $(document).ready(function () {
        $("#List_ValueStream").on('change', function () {
            alert('3 Handler for .change() called.');
        });
    });

/

    $("#<%=List_ValueStream.ClientID%>").change(function () {
          alert('4 Handler for .change() called.');
    });

/

    $("#List_ValueStream").change(function () {
        alert('5 Handler for .change() called.');
    });
7
  • Have you tried removing the runat="server"? Are you getting any errors in the chrome/ff/IE developer consoles? Commented Jan 24, 2013 at 15:12
  • 1
    When you view the HTML source of the page in your browser, is the id actually List_ValueStream? Do you watch the console to check for JavaScript errors? Commented Jan 24, 2013 at 15:12
  • Does it work with a simple <select id="List_ValueStream"> Commented Jan 24, 2013 at 15:13
  • 1
    That's why he's tried using ClientID Commented Jan 24, 2013 at 15:17
  • 2
    Is the $(document).ready() code inside the <script></script> tags used to load jQuery or inside a separate <script> tag after that one? If it's the former, move it to its own <script> tag. Commented Jan 24, 2013 at 15:18

2 Answers 2

7

have you written script between these two lines. Then write your script in a sperate script tag as follows

<script src="http://code.jquery.com/jquery.min.js" type="text/javascript">

</script>


<script src="http://code.jquery.com/jquery.min.js" type="text/javascript">
</script>

<script type="text/javascript">
 $(document).ready(function () {
    $("#<%=List_ValueStream.ClientID%>").change(function () {
        alert('1 Handler for .change() called.');
    });
});
</script>

I think only this can be the reason. other wise it is ok.
You can take the advantage of ClientIDMode=static if you are using asp.net 4.0 or above. it will not change the id of you control as follow

 <asp:TextBox ID="txtEcho2" runat="server" ClientIDMode="Static" /> 

So you can get rid of ClientId

Sign up to request clarification or add additional context in comments.

Comments

4

you can use like this and work well

<asp:DropDownList ID="List_ValueStream" runat="server" Width="195px" onchange="youfunction();"/>

1 Comment

It works, although it's not quite what I need. Thanks though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.