I am developing a server control in C#. I am trying to read via jQuery when the selectedindexchanges on a drop down menu.
All my research has alluded to using the change event. As a result, I built a simple test via an alert to see whether this event gets called correctly. Here is my script:
var builder = new StringBuilder();
builder.Append("$(document).ready(function() {");
builder.Append("$($='_ddlMyTest').change(function() {");
builder.Append("alert('hello');");
builder.Append("}");
builder.Append(");");
builder.Append("}");
builder.Append(");");
I call this script in my control to register startup scripts:
ScriptManager.RegisterStartupScript(Page, GetType(), "myfunction", String.Format("<script type='text/javascript'> {0}</script>", builder), false);
I know jQuery is registered correctly, and the above is registered correctly if I just throw an alert in the $(document).readyI do see it in my browser.
My rendered HTML for that element looks like a normal select. I have also tried passing in the ClientID rather than using the $='_ddlMyTest' to no effect. I have made sure after that this match.
My question is, does this change event work for when the index is changing in an asp.net dropdown?