Test Menu

  • Commentary
  • Deals
  • Coupons

Jun 21, 2011

Calling Existing Javascript from Code Behind

Notes on how to call an existing javascript function from the code-behind.  The "confirmDelete" function below calls a jQuery dialog that will be used to delete records from a datalist.  I'm running this script from the code behind because I want to populated the dialog with values from the datalist record to allow the user to view the data they are about to delete.  The code at the bottom contained in the datalist ItemCommand method and runs when the e.CommandName = "Delete".


ASPX


<script type="text/javascript">
        // increase the default animation speed to exaggerate the effect
        $.fx.speeds._default = 400;
        function confirmDelete() {


            var dlgeditproduct = $(".deleteconfirmdiv").dialog({
                modal: true,
                width: 750,
                height: 450,
                autoOpen: false,
                title: "Are you sure you want to delete this News Release?",
                hide: "explode"
            });


            $(".deleteconfirmdiv").dialog("open");


            dlgeditproduct.parent().appendTo(jQuery("form:first"));


        };
</script>



VB


 Page.ClientScript.RegisterStartupScript(Me.GetType(), "confirmdelete", "confirmDelete();", True)

No comments:

Post a Comment