I have an asp dropdownlist with a few selections and when I select a certain item from the list I want a javascript modal to open up. I have successfully been able to open the modal by using an html button after selecting the specific item from the drop down, but I want one less step.
Here is my code for the index changed event on the Drop down:
protected void ShipTo_Changed(object sender, EventArgs e)
{
foreach (DataListItem dli in cart.Items)
{
DropDownList drpShipto = (DropDownList)dli.FindControl("drpShipto");
if (drpShipto.SelectedItem.Text == "-Add New ShipTo-")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "function", "showDialog('newShipTo')", true);
}
}
}
and here is what I have for the js :
<script>
$(document).ready(function () {
$('#newShipTo').dialog({
autoOpen: false,
draggable: true,
title: "Add New ShipTo",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
$('#editShipTo').dialog({
autoOpen: false,
draggable: true,
title: "Edit ShipTo",
open: function (type, data) {
$(this).parent().appendTo("form");
}
});
});
function showDialog(id) {
$('#' + id).dialog("open");
}
function closeDialog(id) {
$('#' + id).dialog("close");
}
</script>
I know the function works, as I can swap out the call to the function to making a button visible that with the onclick set to showDialog('newShipTo')
Am I just not calling it correctly using the RegistarStartupScript